Skip to content

"Styled" is not working when using production components  #840

@utkarshk384

Description

@utkarshk384

Environment

  • Linaria version: ^3.0.0-beta.4 (@linaria/core) & ^3.0.0-beta.4
  • Bundler (+ version): ^2.56.3(rollup)
  • Node.js version: v14.17.0
  • OS: macOS Bigsur 11.3.1

Description

So I'm currently trying to build a component library using lerna and linaria due to its build time CSS compilation and in doing so I wanted to avoid code duplication so I thought of making a wrapper component that would be used in every component throughout the library.

However, in doing so I can't seem to get past the following error:

Uncaught Error: Using the "styled" tag in runtime is not supported.

Upon further digging, I found out that this error only happens when I try to import a linaria-styled component that is defined in another package.

Example

I have the following imports in the reproducible repo

//src/app.tsx

//Doesn't Work ;(
import { StyledWrapper, StyledComponentType, SpacingType, PropsType } from './wrapper/dist/esm/wrapper/src/wrapper'

//Works! ;)
import { StyledWrapper, StyledComponentType, SpacingType, PropsType } from './wrapper/src/wrapper'; 

The first one is an import from the production build of the wrapper component using rollup and the second one is the component that is straight from the source code. If the first one is active then I get the error that I mentioned above in the browser console and if I use the second code everything seems to compile as expected.

Reproducible Demo

Steps to reproduce

Repo link

  1. Clone the repo by running https://github.com/utkarshk384/repo-linaria.git
  2. Then cd into the directory and yarn install by cd ./repo-linaria && yarn
  3. Run yarn build to build the wrapper component(The custom component wrapper) Then after Successfully created message press ctrl + c since rollup doesn't seem to exit control flow automatically.
  4. Run yarn dev and open your favorite web browser and head to localhost:8080.
  5. Check your web console for the error.

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions