create-react-app icon indicating copy to clipboard operation
create-react-app copied to clipboard

Importing external CSS goes kaboom

Open tristanoneil opened this issue 10 years ago • 9 comments

When I installed hack and then tried importing it I get the following error. 💥💥💥

Error in ./~/hack/dist/hack.css
Module parse failed: /Users/tristanoneil/src/saute/node_modules/hack/dist/hack.css Unexpected token (1:4)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (1:4)
 @ ./src/index.js 11:0-15

Feel free to close if this just isn't how create-react-app is intended to be used but I could see others being bit by this as well so hence the issue.

tristanoneil avatar Jul 22 '16 21:07 tristanoneil

The default config resolves CSS files only located in your src folder: https://github.com/facebookincubator/create-react-app/blob/master/config/webpack.config.dev.js#L70

You can solve this by ejecting the config and removing the line or put another loader for external CSS.

glennreyes avatar Jul 22 '16 21:07 glennreyes

@glennreyes sure that's a fine work around but it seems like it'd be nice to resolve CSS from node_modules as well. ¯(ツ)/¯

tristanoneil avatar Jul 22 '16 21:07 tristanoneil

@glennreyes I think we can just remove that include line for .css. The reason we need that for .js is we don't want babel to transform stuff under node_modules, but for CSS files they should be processed by webpack anyway so it should be fine. Do you want to send a PR?

also cc @gaearon to double check. :)

keyz avatar Jul 22 '16 21:07 keyz

@keyanzhang Sure 😉

glennreyes avatar Jul 22 '16 21:07 glennreyes

Thanks @glennreyes!

keyz avatar Jul 22 '16 22:07 keyz

@glennreyes @keyanzhang 🎉 Yey! Thanks!

tristanoneil avatar Jul 22 '16 22:07 tristanoneil

Should be fixed in 0.2.0 alpha. Please help us test it! https://github.com/facebookincubator/create-react-app/pull/190

gaearon avatar Jul 27 '16 22:07 gaearon

Tested in 0.2.0 alpha and this worked as expected. 🌞

tristanoneil avatar Jul 29 '16 11:07 tristanoneil

FWIW alpha is now stable so newly created projects will just work with this, and old projects can be updated to "react-scripts": "0.2.0".

gaearon avatar Jul 29 '16 12:07 gaearon