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.

NPM Package raises "unexpected token ..." when building with webpack

See original GitHub issue

Describe the bug

Building a react module with an import of three.js fails with the following error:

ERROR in ./~/three/build/three.js
Module parse failed: /home/animesh/Code/Research/mlq-visualizers/molecular_graphs/static/node_modules/three/build/three.js Line 1910: Unexpected token ...
You may need an appropriate loader to handle this file type.
|                       this.viewport.copy(source.viewport);
|                       this.texture = source.texture.clone();
|                       this.texture.image = { ...this.texture.image
|                       }; // See #20328.
| 

To Reproduce

Steps to reproduce the behavior:

  1. Run npm install --save three
  2. Make a webpack file
  3. Write in the rest of the code, following https://www.smashingmagazine.com/2020/11/threejs-react-three-fiber/
  4. Run webpack and see the error

Code

Just importing the module leads to the error.

Live example

JSFiddle examples not included.

Expected behavior

The webpack should either work, since before adding in the three library the rest of react worked great with webpack, or it should raise an error tracable from my code.

Screenshots

image

Platform:

  • Device: [Desktop]
  • OS: [Linux]
  • Three.js version: [0.132.2, 0.133.0]

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
Mugen87commented, Jan 14, 2022

I think it’s okay to rewrite the code without the spread operator.

1reaction
gm112commented, Sep 30, 2021

Your version of webpack is really out of date. Version 1 is really, really old, so I would highly suggest updating your version of Webpack. The current version is 5.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack with react modules giving unexpected token
Been trying to use the react-spin npm module, but when I try and build a bundle.js with webpack, I receive the following error:...
Read more >
Operator results in "Unexpected Token" err when used in ...
If you import a package that uses ?? operator in code, create react app will fail when debugging. ... It builds (npm run...
Read more >
How To Fix Unexpected Token Error for NPM Package in react ...
Are you getting this error with react -leaflet or other packages. If you are then it's most likely related to babel and there...
Read more >
ts-loader - npm
Use webpack like normal, including webpack --watch and webpack-dev-server , or through another build system using the Node.js API.
Read more >
typescript syntaxerror: unexpected token 'export' - You.com
You can fix this by changing to CommonJS, or following the steps outlined in the NodeJS ESM page linked. As for why this...
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