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.

CodeSerializer Can't serialize code for OBJLoader2Parallel worker correctly when threejs is bundled with webpack

See original GitHub issue
Description of the problem

I’m using Threejs in a project with webpack to bundle the code. When I’m trying to use the OBJLoader2Parallel class to load obj files in a web worker, But it failed due to undefined webpack code utils_ObjectManipulator_js__WEBPACK_IMPORTED_MODULE_0_ in the worker code.

After some investigation, I find out that the worker code are generated on the fly using CodeSerializer based on code like WorkerRunner.js, ObjectManipulator.js and OBJLoader2Parser.js, which are all bundled into the same bundle file by webpack.

But due to ObjectManipulator.js is imported to WorkerRunner.js file, the code below: ObjectManipulator.applyProperties( parser, payload.params ); in WorkerRunner.js will be converted to: _utils_ObjectManipulator_js__WEBPACK_IMPORTED_MODULE_0__["ObjectManipulator"].applyProperties( parser, payload.params ); by webpack.

Then, when the OBJLoader2Parallel is building the worker code with CodeSerializer, the code above will be copied directly and it can’t resolve utils_ObjectManipulator_js__WEBPACK_IMPORTED_MODULE_0_[“ObjectManipulator”] to the ObjectManipulator object. This makes the worker fail.

Three.js version
  • Dev
  • r109
Browser
  • All of them
  • Chrome
  • Firefox
  • Internet Explorer
OS
  • All of them
  • Windows
  • macOS
  • Linux
  • Android
  • iOS
Hardware Requirements (graphics card, VR Device, …)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
geoff-harpercommented, Jan 8, 2020

I’ve set up a test repo at https://github.com/geoff-harper/obj-parallel-cra-test. I can’t speak to CRA’s minification process but you can yarn eject to see their webpack config. It looks like they’re using https://github.com/terser/terser under the hood

1reaction
manyoocommented, Oct 30, 2019

Thanks! @kaisalmen

Read more comments on GitHub >

github_iconTop Results From Across the Web

Three.js cube is not rendering after bundling – Webpack ...
I'm trying to integrate three.js with wordpress via webpack. The problem is that, 3d cube is not appearing inside canvas.
Read more >
Failed to convert into json - Questions - three.js forum
Hello Three js team, I am trying to convert this imagery provided by three-geo into an json object but getting this error by...
Read more >
How to reduce bundle size with Webpack? - three.js forum
As far as I understand, three-shaking will not work until three.js is written using ES6 classes. BoxBufferGeometry and BoxGeometry have been ...
Read more >
Bundling threejs project with DRACOLoader (webworker)
I am trying to bundle my threejs project which uses DRACOLoader file. It creates web-worker in runtime with BLOB url. I tried webpack...
Read more >
Webpack cant resolve and point to my node_modules
Create package.json · Install webpack npm i --save-dev webpack webpack-cli · Install Three.js · Create index.html with following code · Create a src...
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