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.

Requiring CSS files from node_modules fails with SyntaxError: Unexpected token

See original GitHub issue

Steps 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:closed
  • Created 8 years ago
  • Reactions:2
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

8reactions
chetoncommented, Dec 23, 2015

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 the node_modules directory, like so:

browserify index.js -g browserify-css -o bundle.js
6reactions
jlaustillcommented, Aug 28, 2016

I also figured out that you can use it with gulp, the api isn’t documented well either

.transform({global: true}, require("browserify-css"))
Read more comments on GitHub >

github_iconTop 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 >

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