developit / web-worker

Consistent Web Workers in browser and Node.
https://npm.im/web-worker
Apache License 2.0
1.06k stars 55 forks source link

Module not found: Error: Can't resolve 'worker_threads' in 'xxxx\node_modules\web-worker\cjs' #31

Open llittlefoxx opened 2 years ago

llittlefoxx commented 2 years ago

web-worker version: 1.2.0 node version: 16.13.2 npm version: 8.1.2

Running a react web application gives the following error:

ERROR in ../node_modules/web-worker/cjs/node.js Module not found: Error: Can't resolve 'worker_threads' in 'D:\customers\GEOGRAT\gisx3-client\node_modules\web-worker\cjs' @ ../node_modules/web-worker/cjs/node.js 20:16-41 @ ../node_modules/geotiff/dist-node/worker/decoder.js @ ../node_modules/geotiff/dist-node/pool.js @ ../node_modules/geotiff/dist-node/geotiff.js @ ../node_modules/ol/source/GeoTIFF.js @ ../node_modules/ol/source.js @ ./util/openlayers/specialLayers.ts @ ./util/openlayers/createLayer.ts @ ./ui/map/MapLayer.tsx @ ./ui/map/MapContainer.tsx @ ./ui/screens/MapScreenContainer.tsx @ ./ui/screens/AppScreen.tsx @ ./ui/screens/AppContainer.tsx @ ./index.tsx @ multi ./polyfills.ts ./index.tsx

jonblatho commented 2 years ago

I'm running into this too. Did you get past this @llittlefoxx?

sripwoud commented 2 years ago

Had the same issue, I think it is because of the different export/import flavors depending on where you plan to use web-worker: https://github.com/developit/web-worker/blob/29fef9775702c91887d3d8733e595edf1a188f31/package.json#L7-L11

I fixed it by tweaking my webpack config:

 resolve: {
      conditionNames: ['browser', ...],
      ...