Error trying to run "npm run prod" from within a shell script
Hello,
I'm running npm run prod from within a docker container. If I run it manually on the command line tool, everything woks fine.
But when I run the same command from within a shell script, it fails.
> prod
> npm run websocket-prod && npm run production
> websocket-prod
> node prepare-build.js && cross-env process.env.target=server process.env.source_map=no NODE_ENV=production node_modules/webpack/bin/webpack.js --config=node_modules/laravel-mix/setup/webpack.config.js
node:events:498
throw er; // Unhandled 'error' event
^
Error: spawn node_modules/webpack/bin/webpack.js ENOENT
at Process.ChildProcess._handle.onexit (node:internal/child_process:283:19)
at onErrorNT (node:internal/child_process:478:16)
at processTicksAndRejections (node:internal/process/task_queues:83:21)
Emitted 'error' event on ChildProcess instance at:
at Process.ChildProcess._handle.onexit (node:internal/child_process:289:12)
at onErrorNT (node:internal/child_process:478:16)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
errno: -2,
code: 'ENOENT',
syscall: 'spawn node_modules/webpack/bin/webpack.js',
path: 'node_modules/webpack/bin/webpack.js',
spawnargs: [ '--config=node_modules/laravel-mix/setup/webpack.config.js' ]
}
Before that I had an error with missing cross-env which I was able to resolve by intalling cross-env gloablly within the docker container. Now I am stuck with the above error.
You can try and remove the node_modules folder using rm -rf node_modules and let the script install all the packages. Because it might be permissions issue.
@Teleogrid You said you ran npm run prod before you started the script. So the node_modules is already there, but with different permissions is the point I am trying to make.
Or are you completely destroying the container with the filesystem and then rebuilding it over again?
@Nakov I'm completly rebuilding ... but I discovered that now it also does not work if I run it manually anymore ... I'm just checking what I did differently ...
So as I do not want to have non-production packages on the live server, I now decided to first install all packages in order to build javascript bundles and then do a npm prune --production before pushing it to the server.
# install all packages so bundles can be built
npm install
npm run prod
# remove unnecessary dev packages from production build
npm prune --production
@Sinnbeck Ah yes, true. But I also have a node server running in the same project using server side imports. I'm not sure, but I belief those imports are using node_modules directory. I have to check.