Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use css-in-js solution with react template #135

Closed
wcastand opened this issue May 13, 2020 · 3 comments
Closed

Cannot use css-in-js solution with react template #135

wcastand opened this issue May 13, 2020 · 3 comments

Comments

@wcastand
Copy link

Describe the bug

I know the react template is not a priority and it's probably specific to react but just in case.
I'm trying this out with typescript and the react template and was setting up styled-components and I got this error in the console of chrome.

Uncaught SyntaxError: The requested module '/@modules/hoist-non-react-statics/dist/hoist-non-react-statics.cjs.js' does not provide an export named 'default'

Reproduction

repo

yarn
yarn dev

System Info

  • required vite version: vite v0.14.3
  • required Operating System: macOS Catalina 10.15.4
  • required Node version: v12.16.3
  • Optional:
    • yarn version: v1.16.0
    • react version: 16.13.1
    • styled-components version : 5.1.0
@wcastand wcastand added the bug label May 13, 2020
@yyx990803
Copy link
Member

yyx990803 commented May 13, 2020

Vite by default expects all dependencies to ship ES modules, in this case, the dependency in question is using cjs syntax.

What you can do for now is use Snowpack (1.x) alongside Vite - yarn add -D snowpack then run a script of snowpack install to pre-bundle styled-components into a single ESM file. Vite will provide built-in support for this soon.

@nc
Copy link

nc commented Feb 2, 2021

Any update on this - looking to use styled-components with Vite, but right now it's reloading the page for every style change vs HMR.

@yyx990803
Copy link
Member

@nc this issue is way out of date. Your issue is likely completely different, so please open new ones with proper reproduction instead of commenting on old ones.

@vitejs vitejs locked as resolved and limited conversation to collaborators Feb 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants