NPM Package raises "unexpected token ..." when building with webpack
See original GitHub issueDescribe 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:
- Run
npm install --save three
- Make a webpack file
- Write in the rest of the code, following https://www.smashingmagazine.com/2020/11/threejs-react-three-fiber/
- 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
Platform:
- Device: [Desktop]
- OS: [Linux]
- Three.js version: [0.132.2, 0.133.0]
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (1 by maintainers)
Top 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 >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 it’s okay to rewrite the code without the spread operator.
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.