react-toolbox/react-toolbox-example

Can't build with cross-env - Error: spawn webpack ENOENT

ktmn opened this issue · 7 comments

ktmn commented

Cloned repo, ran install, ran start - works fine. Ran build - get this error:

λ npm run build

> react-toolbox-example@0.11.3 build C:\...\react-toolbox-example
> cross-env NODE_ENV=production UV_THREADPOOL_SIZE=100 webpack --config ./webpack.config.file

events.js:141
      throw er; // Unhandled 'error' event
      ^

Error: spawn webpack ENOENT
    at exports._errnoException (util.js:837:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:178:32)
    at onErrorNT (internal/child_process.js:344:16)
    at doNTCallback2 (node.js:429:9)
    at process._tickCallback (node.js:343:17)
    at Function.Module.runMain (module.js:477:11)
    at startup (node.js:117:18)
    at node.js:951:3

npm ERR! Windows_NT 10.0.10240

So I tried to set node env manually

SET NODE_ENV=production && webpack --config ./webpack.config.file

But it didn't work or something, because the built react-toolbox.js file will still look for __webpack_hmr EventSource, so hmr appears to be still enabled.

The problem also appears in my actual project, that I used react-toolbox in. I eliminated any trace of hmr from my source files yet it still kept showing up - turns out it was from the source of react-toolbox. So how do I let it know that the "node env" is "production"?

Also tried to do it in the webpack.config.file.js file

'process.env.NODE_ENV': JSON.stringify('production')

Nothing changed.

That's weird. I noticed the HMR issue and added the production env variable to the script. Then, I made it work properly. As I said in other issues, I have no Windows machine and can't test it but the issue is clearly related to how env variables are set in a Windows env.

For now we need to set the production env variable to avoid including HMR and also to increase the thread pool to overcome a node-sass issue that makes the compilation freeze. It's important to have it working across different OS envs and I thought it was solved with the cross-env PR.

If anybody can help with the Windows support it would be very welcome!

@NogsMPLS played a lot with this kind of issues, maybe he can help!

Hey @ktmn I noticed this issue was created 4 days ago. This is right around the time that I had a PR get merged into the cross-env repo.

However, I don't know if you npm installed before or after that release for cross-env was tagged that day.

If possible, could you pull/fetch the latest from this repo and then npm install again and make sure in your node_modules folder that the cross-env package.json has 1.0.4 as the version number?

It should work, as the whole reason I put in the PR to cross-env was because I was getting ENOENT issues before as well.

SIDE NOTE: the current react-toolbox-example repo has npm scripts run against webpack.config.file but that doesn't exist anymore, so there is another error happening around that, i'll submit a PR here in a minute to change it to just webpack.config

Great! @ktmn can you try it?

ktmn commented

My bad I completely forgot to post here, but I resolved the issue by reinstalling react-toolbox. So basically, yes, what Nogs said. And now I understand why it actually worked. Thanks!

Great!

I faced a similar issue and the fix was to make sure the fields of the WebpackPwaManifest matched that of your package.json