On a fresh Laravel 5.4 install, I just removed bootstrap-sass from package.json and ran npm install, when I try to run npm run dev, what I got at first was Error: Cannot find module '/home/vagrant/projectname/webpack.mix', so I run 'sudo npm install webpack --save', after that when I run npm run dev again I get "Cannot find module 'which'", when I install that module manually and try again to run npm run dev, yet another module is missing, so on and so forth, whenever I run npm install I expect all dependencies to be installed but that's not the case, I've spend hours trying to troubleshoot this but there must be something that I am unaware of, anyway for my environment I have:
- Windows host machine
- Virtual box with CentOS
- Laravel -> v5.4.30
- PHP -> 7.1
- Node -> v8.2.1
- Npm -> v5.3.0
- Laravel Mix -> 1.3.0
Since I am on a Windows host, I had to symlink my node_modules folder from inside the virtual machine to a file in the project folder, so all the node_modules are getting installed inside /home/vagrant/projectname/node_modules, and that is symlinked to /vagrant/projectname/node_modules(is a symlink file), note that the latter path is a completely different path.
So the error "Cannot find module '/home/vagrant/projectname/webpack.mix'" is because that file doesn't actually exist there, after I run npm install webpack --save that error is no more, even tho that webpack.mix file it was looking is still not there which I find weird.
Initial npm installation:
sudo npm install
> [email protected] install /vagrant/tatts/node_modules/node-sass
> node scripts/install.js
Downloading binary from https://github.com/sass/node-sass/releases/download/v4.5.3/linux-x64-57_binding.node
Download complete ] - :
Binary saved to /home/vagrant/tatts/node_modules/node-sass/vendor/linux-x64-57/binding.node
> [email protected] postinstall /vagrant/tatts/node_modules/uglifyjs-webpack-plugin
> node lib/post_install.js
> [email protected] postinstall /vagrant/tatts/node_modules/node-sass
> node scripts/build.js
Binary found at /home/vagrant/tatts/node_modules/node-sass/vendor/linux-x64-57/binding.node
Testing binary
Binary is fine
> [email protected] postinstall /vagrant/tatts/node_modules/gifsicle
> node lib/install.js
? gifsicle pre-build test passed successfully
> [email protected] postinstall /vagrant/tatts/node_modules/mozjpeg
> node lib/install.js
? The `/home/vagrant/tatts/node_modules/mozjpeg/vendor/cjpeg` binary doesn't seem to work correctly
? mozjpeg pre-build test failed
? compiling from source
? Error: autoreconf -fiv && ./configure --disable-shared --prefix="/home/vagrant/tatts/node_modules/mozjpeg/vendor" --bindir="/home/vagrant/tatts/node_modules/mozjpeg/vendor" --libdir="/home/vagrant/tatts/node_modules/mozjpeg/vendor" && make --jobs=2 && make install --jobs=2
Command failed: autoreconf -fiv
/bin/sh: autoreconf: command not found
at ChildProcess.exithandler (child_process.js:270:12)
at emitTwo (events.js:125:13)
at ChildProcess.emit (events.js:213:7)
at maybeClose (internal/child_process.js:921:16)
at Socket.stream.socket.on (internal/child_process.js:348:11)
at emitOne (events.js:115:13)
at Socket.emit (events.js:210:7)
at Pipe._handle.close [as _onclose] (net.js:549:12)
> [email protected] postinstall /vagrant/tatts/node_modules/optipng-bin
> node lib/install.js
? optipng pre-build test passed successfully
> [email protected] postinstall /vagrant/tatts/node_modules/pngquant-bin
> node lib/install.js
? The `/home/vagrant/tatts/node_modules/pngquant-bin/vendor/pngquant` binary doesn't seem to work correctly
? pngquant pre-build test failed
? compiling from source
? pngquant built successfully
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
added 1301 packages in 161.975s
When I run npm install again I get:
sudo npm install
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/laravel-mix/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/webpack/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
added 229 packages, removed 49 packages and moved 219 packages in 40.47s
Note: I don't think that these warnings are a problem, I had those before when we were using gulp with Laravel 5.3 and 5.2.
And now when I run npm run dev again I get this:
npm run dev
> @ dev /vagrant/tatts
> npm run development
> @ development /vagrant/tatts
> cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js
module.js:487
throw err;
^
Error: Cannot find module 'which'
at Function.Module._resolveFilename (module.js:485:15)
at Function.Module._load (module.js:437:25)
at Module.require (module.js:513:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/home/vagrant/tatts/node_modules/cross-env/node_modules/cross-spawn/lib/util/resolveCommand.js:4:13)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ development: `cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @ development script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/vagrant/.npm/_logs/2017-07-22T16_07_38_765Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ dev: `npm run development`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @ dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/vagrant/.npm/_logs/2017-07-22T16_07_38_791Z-debug.log
And as mentioned when I install that module I get that yet another module is missing, and I install that one, and another one is missing, it goes on for a really long list. I need a way to install all those missing modules.
When I run npm list I find that so many dependencies are missing or unmet, I want to install those, but I don't want to do it manually cause there's so many of them.
Also when I try to install Laravel Mix via npm I get this weird error:
sudo npm install laravel-mix
> [email protected] install /vagrant/tatts/node_modules/node-sass
> node-gyp rebuild
gyp WARN EACCES user "root" does not have permission to access the dev dir "/root/.node-gyp/8.2.1"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/vagrant/tatts/node_modules/node-sass/.node-gyp"
net.js:696
throw new TypeError(
^
TypeError: Invalid data, chunk must be a string or buffer, not undefined
at Socket.write (net.js:696:11)
at [eval]:1:16
at ContextifyScript.Script.runInThisContext (vm.js:44:33)
at Object.runInThisContext (vm.js:116:38)
at Object.<anonymous> ([eval]-wrapper:6:22)
at Module._compile (module.js:569:30)
at evalScript (bootstrap_node.js:432:27)
at startup (bootstrap_node.js:139:9)
at bootstrap_node.js:575:3
gyp: Call to 'node -e "process.stdout.write(require('../package.json').libsass)"' returned exit status 1 while in src/libsass.gyp. while loading dependencies of binding.gyp while trying to load binding.gyp
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack at ChildProcess.onCpExit (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:336:16)
gyp ERR! stack at emitTwo (events.js:125:13)
gyp ERR! stack at ChildProcess.emit (events.js:213:7)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)
gyp ERR! System Linux 3.10.0-514.26.2.el7.x86_64
gyp ERR! command "/usr/bin/node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/vagrant/tatts/node_modules/node-sass
gyp ERR! node -v v8.2.1
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/webpack/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2017-07-22T17_11_42_568Z-debug.log
So here's what I tried:
- I destroyed that vagrant box, rebuilt it again
- I deleted the entire Laravel project and created it again
- I tried installing npm helpers that would install missing modules but 3 of them were completely useless.
- I removed the node_modules folder + symlink, removed package-lock.json cleared npm cache and ran npm install again(This was recommended by JefferyWay on one of the github issues).
None of the above solved the issue.
Needless to say that I am extremely frustrated that I can't solve this issue, been going on with this for 4+ hours and it's taken it's toll on me, I am all ears for all and any suggestions, thanks.