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.

Importing css causes obscure error in browserify

See original GitHub issue

Overview

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

  1. Extract the files from the attached archive.
  2. npm install
  3. npm install -g gulp if not already installed
  4. gulp

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.

reproduce.zip

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:3
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
educastellanocommented, Apr 10, 2018

I think the CSS should be imported outside the component, so the user can import it in whatever bundler is using, i.e.:

import Timeline from 'react-visjs-timeline'
import 'vis/dist/vis.min.css'

ReactDOM.render(
  <Timeline />,
  document.getElementById('root')
);

1reaction
zoeesilcockcommented, Apr 18, 2018

@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.

Read more comments on GitHub >

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

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