Requiring CSS files from node_modules fails with SyntaxError: Unexpected token
See original GitHub issueSteps to reproduce in an empty folder
npm install browserify-css
npm install leaflet
echo 'require("leaflet/dist/leaflet.css")' > index.js
browserify index.js -t browserify-css -o bundle.js
/tmp/leaflet-css/node_modules/leaflet/dist/leaflet.css:3 .leaflet-map-pane, ^ ParseError: Unexpected token
Copying the CSS file to the root works
cp node_modules/leaflet/dist/leaflet.css leaflet.css
echo 'require("./leaflet.css")' > index.js
browserify index.js -t browserify-css -o bundle.js
Is there anything we can do about it? Or does browserify treat these files differently and they don’t even reach the transform?
Issue Analytics
- State:
- Created 8 years ago
- Reactions:2
- Comments:9 (4 by maintainers)
Top Results From Across the Web
SyntaxError: Unexpected token '.' when bundling a css file
The error makes me believe you try to compile your CSS files as JavaScript. That can't work, CSS is not JS. import is...
Read more >[Solved]-CSS Modules - unexpected token-Reactjs
CSS Modules are turned on for files ending with the .module.css extension. So, rename the CSS file from style.css to style.module.css and change...
Read more >How to configure CSS and CSS modules in webpack
ERROR in ./src/styles.css 1:0 Module parse failed: Unexpected token (1:0) You may need an appropriate loader to handle this file type, currently no...
Read more >How to fix issue #1: SyntaxError, unexpected token loading CSS
This would work if we use the external method and insert the CSS file in the html template as string on the server,...
Read more >SyntaxError Invalid or unexpected token - How to SSR images ...
I get an error "SyntaxError: Invalid or unexpected token". ... to their directories as.js files, each with their own CSS/Images/whatever ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Note that the
-t
option will only transform module on top-level files.In your case, you can use the
-g
option to transform module in thenode_modules
directory, like so:I also figured out that you can use it with gulp, the api isn’t documented well either