question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

linaria/loader issue with TypeScript

See original GitHub issue

Do you want to request a feature or report a bug? bug

What is the current behavior? linaria/loader skips files that uses styled or css only with generic type parameter (TypeScript).

If the current behavior is a bug, please provide the steps to reproduce and a minimal repository on GitHub that we can yarn install and yarn test. Create new component file, inside create styled React component providing generic parameter for props type, e.g.:

// imports, etc. (...)

export type TitleProps = {
  backgroundColor: string;
}

export const Title = styled.h1<TitleProps>`
  background: ${props.backgroundColor};
`;

Reproducing repo: https://github.com/radoslaw-medryk/linaria-example

npm install
npm run start

What is the expected behavior? Component would be processed by linaria/loader.

What is the actual behavior? Instead, linaria/loader ignores this component file when building, because it doesn’t pass this regex test: linaria/src/transform.js:54

if (
    !/\b(styled[\s\n]*(\([\s\S]+\)|\.[\s\n]*[a-z0-9]+)|css)[\s\n]*`/.test(
      content
    )
  ) {
    return {
      code: content,
      sourceMap: inputSourceMap,
    };
  }

This regex doesn’t expect generic type parameters, and thinks this file doesn’t use linaria.

Please provide your exact Babel configuration and mention your Linaria, Node, Yarn/npm version and operating system. "linaria": "^1.0.0-beta.0"

.babelrc

{
    "presets": [
        "@babel/react",
        "@babel/typescript",
        ["linaria/babel", {
            "displayName": true
        }]
    ],
    "plugins": []
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
radoslaw-medrykcommented, Dec 10, 2018

I can do PR to fix this. Would be a good intro into contributing to project with great potential 😃

0reactions
satya164commented, Dec 10, 2018

Maybe we can just check for styled and css. They should be guaranteed to be in the file. It’ll result in more false positives, but should be more reliable.

Read more comments on GitHub >

github_iconTop Results From Across the Web

@linaria/webpack-loader - npm
@linaria/webpack-loader. TypeScript icon, indicating that this package has built-in type declarations. 4.1.10 • Public • Published 19 days ...
Read more >
Using Linaria for faster CSS-in-JS in React apps
In this article, we will explore how to use a zero-runtime CSS-in-JS library called Linaria in React applications.
Read more >
@linaria/webpack-loader | Yarn - Package Manager
Fast, reliable, and secure dependency management.
Read more >
Use CSS-in-JS | Taro 文档
API that approximates styled-components; TypeScript support; Zero runtime ... linaria/loader options refer to https://github.com/callstack/linaria/blob/ ...
Read more >
Linaria Setupメモ(React / TypeScript) - Zenn
Linaria は現状 babelが必須なので、. TypeScriptの型チェック -> ts-loaderにやらせる; Linaria用の処理 & ES5へのトランスパイル -> Babelにやらせる.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found