Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't resolve worker threads #223

Closed
mpaccione opened this issue Apr 5, 2021 · 8 comments
Closed

Can't resolve worker threads #223

mpaccione opened this issue Apr 5, 2021 · 8 comments
Labels
🪲 bug Something isn't working

Comments

@mpaccione
Copy link

mpaccione commented Apr 5, 2021

Hello, I am using Webpack on clientside. I have no issues with my other packages.
I am receiving this error.

Working with my public repo here:
https://github.com/mpaccione/everest_flight_sim/tree/debugger-mapbox-tiles

in /client dir
npm install
edit dirname path in webpack.config.js
npm run build

Any thoughts on the issue? Also, unless I import Three myself I get this error: Error: THREE is not defined
at eval (mapbox-gl.js:30)

WARNING in ./node_modules/threebox-plugin/src/objects/fflate.min.js 6:538-570
Module not found: Error: Can't resolve 'worker_threads' in 'C:\Projects\everest_flight_sim\client\node_modules\threebox-plugin\src\objects'
resolve 'worker_threads' in 'C:\Projects\everest_flight_sim\client\node_modules\threebox-plugin\src\objects'
  Parsed request is a module
  using description file: C:\Projects\everest_flight_sim\client\node_modules\threebox-plugin\package.json (relative path: ./src/objects)
    Field 'browser' doesn't contain a valid alias configuration
    resolve as module
      looking for modules in C:/Projects/everest_flight_sim/client/node_modules
        single file module
          using description file: C:\Projects\everest_flight_sim\client\package.json (relative path: ./node_modules/worker_threads)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              C:\Projects\everest_flight_sim\client\node_modules\worker_threads doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              C:\Projects\everest_flight_sim\client\node_modules\worker_threads.js doesn't exist
            .json
              Field 'browser' doesn't contain a valid alias configuration
              C:\Projects\everest_flight_sim\client\node_modules\worker_threads.json doesn't exist
            .wasm
              Field 'browser' doesn't contain a valid alias configuration
              C:\Projects\everest_flight_sim\client\node_modules\worker_threads.wasm doesn't exist
        C:\Projects\everest_flight_sim\client\node_modules\worker_threads doesn't exist
ModuleNotFoundError: Module not found: Error: Can't resolve 'worker_threads' in 'C:\Projects\everest_flight_sim\client\node_modules\threebox-plugin\src\objects'
    at C:\Projects\everest_flight_sim\client\node_modules\webpack\lib\Compilation.js:1668:28
    at C:\Projects\everest_flight_sim\client\node_modules\webpack\lib\NormalModuleFactory.js:712:13
    at eval (eval at create (C:\Projects\everest_flight_sim\client\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:10:1)
    at C:\Projects\everest_flight_sim\client\node_modules\webpack\lib\NormalModuleFactory.js:273:22
    at eval (eval at create (C:\Projects\everest_flight_sim\client\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:9:1)
    at C:\Projects\everest_flight_sim\client\node_modules\webpack\lib\NormalModuleFactory.js:402:22
    at C:\Projects\everest_flight_sim\client\node_modules\webpack\lib\NormalModuleFactory.js:117:11
    at C:\Projects\everest_flight_sim\client\node_modules\webpack\lib\NormalModuleFactory.js:628:24
    at C:\Projects\everest_flight_sim\client\node_modules\webpack\lib\NormalModuleFactory.js:782:8
    at C:\Projects\everest_flight_sim\client\node_modules\webpack\lib\NormalModuleFactory.js:902:5
 @ ./node_modules/threebox-plugin/src/objects/loaders/FBXLoader.js 2:15-42
 @ ./node_modules/threebox-plugin/src/objects/loadObj.js 9:18-51
 @ ./node_modules/threebox-plugin/src/Threebox.js 17:15-46
 @ ./node_modules/threebox-plugin/main.js 2:14-39
 @ ./src/index.mjs 7:0-43 11:12-20 308:18-26 311:22-30

2021-04-05 16:22:59: webpack 5.30.0 compiled with 1 warning in 5451 ms (77006e2629a9e3bbfaba)
@mpaccione mpaccione added the 🪲 bug Something isn't working label Apr 5, 2021
@jscastro76
Copy link
Owner

Hi @mpaccione,
Thanks for using Threebox!
The problem seems to be with the reference of worker_theeads required from fflate, currently needed for the new FBXLoader included in threejs r127.
I’ll take a look to it

@jscastro76
Copy link
Owner

I was able to solve it in my bundle with browserify, ignoring the reference using browserify --i worker_threads, so I guess you should have an equivalent command in webpack. BTW, I've just opened an issue in fflate repo, to see if there's any option to solve it from the file itself

@jscastro76
Copy link
Owner

jscastro76 commented Apr 6, 2021

I have found a workaround, and apparently it works also with browserify without adding any ignore parameter and of course still functional for the browser use.

Editing the fflate.min.js file...

/// instead of var e = {}, assign e to eval
function(_f){"use strict";var e=eval;...

///then... use the e to eval the require first 
  try{e("require('worker_threads')").Worker}

This thread game me the clue, but specially this tweet

I'm uploading this change now, but it won't be yet at the published module version in npm until v2.2.2

jscastro76 added a commit that referenced this issue Apr 6, 2021
@mpaccione
Copy link
Author

Hi JS,

Thanks for such a quick response on this.
I'm glad that this issue has been resolved in the future version.

I'm unsure whether or not the warning prevents the code from executing because the build still compiles. I will say that using Webpack I seriously cannot run this npm package as an ES6 module import. I had specifically moved away from browserify to webpack and I do not plan to go back after putting the time in already. Overall I'm not a fan of commonJS modules.

Anyways, I want you to know that in my webpack configuration all the other modules work. The official Three js and Mapbox modules work. Threebox definitely absolutely is a no go on my import. My backup plan is to include it in the .html file but...fwiw it may be something to check into. I'm not a webpack expert but since my other modules check out...

import { Threebox } from "threebox-plugin/dist/threebox.js";
This results in UNDEFINED

import { Threebox } from "threebox-plugin";
This results in Error: THREE is not defined at eval (mapbox-gl.js:30)

@jscastro76
Copy link
Owner

@mpaccione that's up to you, I'm not pretending you to use Threebox!

But just to clarify, the issue is not in Threebox, it's in THREE.FBXLoader. You surely can import Three.js because it doesn't include THREE.FBXLoader but you'll have the same issue if you try to bundle it to load .fbx objects. Indeed, as you can see in the issue I opened at fflate, the owner of the repo already foresaw the problem when started to collaborate with threejs, because the issue is in the minified version of fflate, fflate.min.js... read below...

Actually, I foresaw this issue and provided an unminified ESM build and an unminified CJS build to avoid the problem. I was hoping that nobody would ever use Webpack on the UMD build; it was meant specifically for direct users. Could you try replacing this line with a require call to this CJS build?

I was about to report the issue to threejs, but I think it doesn't deserve the time as I have already solved it here, and you decide not to use threebox, which is perfectly fine!

Closing this issue then!

jscastro76 added a commit that referenced this issue Apr 11, 2021
Minor version by [@jscastro76](https://github.com/jscastro76), some enhancements and bugs.

**WARNING**: This version updates to Mapbox **2.2.0**. Despite v1.11.1 still supported, if used, some features from mapbox v.2.0.1 won't be obviously available such as sky layers.
**Known issue**: `BuildingShadow` wont work as the definition of the layers has changed.

#### ✨ Enhancements

Add a better light for night on 14-buildingshadow.html example #118
- #146 Update to Mapbox 2.2
  - #225 Mapbox 2.2: Update Depth calculation keeping compatibility with previous versions
  - #226 Mapbox 2.2: Update all the examples (14-buildingshadow & 17-azuremaps not updated)
  - #232 Mapbox 2.2: Add sky layer as an option in threebox
  - Updated example [07-alignmentTest.html](https://github.com/jscastro76/threebox/blob/master/examples/07-alignmentTest.html)
  - Updated example [12-add3dmodel.html](https://github.com/jscastro76/threebox/blob/master/examples/12-add3dmodel.html)
  - Updated example [13-eiffel.html](https://github.com/jscastro76/threebox/blob/master/examples/13-eiffel.html)
- #224 Ignore worker_threads
- #229 tb.dispose() in dev mode not working. It was removed from three.js but not included in migration guide.
- #234 Update all the examples to include antialias: true in the webglcontext

#### 🪲 Bug fixes
- #223 Can't resolve worker threads
- #230 Module not found: Can't resolve 'worker_threads' (duplicated #223)

#### 📝 Documentation
- Updated [documentation](/examples/readme.md) (Added a note on the examples updated to Mapbox 2.2.0)
- Updated [Threebox documentation](/docs/Threebox.md) (public cdns data, `sky` attribute and property, `tb.createSkyLayer`, `tb.getSunSky`, `tb.updateSunSky`, `tb.updateLightHelper`, )
- Updated [Examples](/examples) documentation (new sky layers in 7, 12, 13).
@jscastro76
Copy link
Owner

@mpaccione this is already uploaded to v.2.2.2 version of the npm module if you want to use it

@mpaccione
Copy link
Author

mpaccione commented Apr 14, 2021

@jscastro76 Nice work on the worker_threads fix. Now in 2.2.2 it is no problem.

Thank you kindly and looking forward to learning more about Threebox. Unfortunately it still returns undefined at the import from the docs directory... I had also tried import { Threebox } from "threebox-plugin" which returns and is not undefined. However then Three is missing. I had tried importing three separately but it didn't work to load the basic doc example.

@jscastro76
Copy link
Owner

Not sure what's the issue you're facing, the module is imported properly in ten other projects.

you have also an example in vue.js that uses threebox as a module.

Regarding THREE, is bundled in Threebox, so it should be accessible using

import {THREE} from "threebox-plugin"

or

import {THREE} from "threebox-plugin/dist/threebox.js"

Hope it helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🪲 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants