Importing css causes obscure error in browserify
See original GitHub issueOverview
When I attempt to import react-visjs-timeline
and then transform my source with browserify
, it says “Error runing browserify Unexpected token undefined”.
Package versions
react-visjs-timeline: 1.4.0 vis version: 4.21.0 browserify version: 13.3.0
Steps to reproduce
- Extract the files from the attached archive.
npm install
npm install -g gulp
if not already installedgulp
Code Snippet
Output
$ gulp
[15:14:01] Using gulpfile ~/test/gulp/gulpfile.js
[15:14:01] Starting 'default'...
[15:14:01] Starting 'browserify'...
[15:14:01] Finished 'browserify' after 1.2 ms
[15:14:01] Finished 'default' after 2.39 ms
events.js:163
throw er; // Unhandled 'error' event
^
SyntaxError: Unexpected token
If I remove the require(... .css)
line from node_modules/react-visjs-timeline/build/index.js
, then the output is what I expect.
$ gulp
[15:16:38] Using gulpfile ~/test/gulp/gulpfile.js
[15:16:38] Starting 'default'...
[15:16:38] Starting 'browserify'...
[15:16:38] Finished 'browserify' after 1.23 ms
[15:16:38] Finished 'default' after 2.19 ms
Ran browserify and wrote output
I am using browserify-css
which seems like it should handle the import of css, but it is clearly not doing that.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:7 (2 by maintainers)
Top Results From Across the Web
reactjs - Unable to import css file with es6 syntax using Grunt ...
I have problem with browserify Grunt task and transform options. I am using React and in one of the component I need to...
Read more >Webpack or Browserify & Gulp: Which Is Better? - Toptal
In this article, Toptal Freelance Software Engineer Eric Grosse shows us how various combinations of the popular tools Webpack, Browserify, Gulp and Npm...
Read more >Common Error Details - Snowpack
If you are using TypeScript, this error could occur if you are importing or exporting something that only exists in TypeScript (like a...
Read more >How to solve the "is not a function" error in JavaScript
This can cause, in some cases, an error like this: TypeError: require(...) is not a function. That's a weird error, right?
Read more >API - esbuild
For example, the js loader interprets the file as JavaScript and the css loader ... so they don't cause errors when the bundler...
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 FreeTop 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
Top GitHub Comments
I think the CSS should be imported outside the component, so the user can import it in whatever bundler is using, i.e.:
@educastellano I agree that the component should not contain a require to the CSS file from the vis package. It makes the assumption that the build environment knows how to handle CSS requires inside of node_modules. I would very much prefer having a way to import just the component without the CSS so I can handle that in what would be a suitable way for my project.
@jdehaan Did you find a solution when using Webpack? I’ve tried in all sorts of ways, but I can’t get Webpack to handle the fact that it’s trying to require the CSS when doing server side rendering. I get the feeling that this is by design as npm packages are supposed to be self contained and not require this type of transformation.