laravel-mix: Cannot find module 'node-sass' - Fresh laravel 5.4 install

I just created a fresh Laravel 5.4 project using Laravel Homestead on a Windows machine. I ran npm install successfully, but am running into issues with npm run dev. Here is my output:


Module build failed: Error: Cannot find module 'node-sass'
    at Function.Module._resolveFilename (module.js:470:15)
    at Function.Module._load (module.js:418:25)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/home/vagrant/Code/CSE356/node_modules/sass-loader/index.js:4:12)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at loadLoader (/home/vagrant/Code/CSE356/node_modules/loader-runner/lib/loadLoader.js:13:17)
    at iteratePitchingLoaders (/home/vagrant/Code/CSE356/node_modules/loader-runner/lib/LoaderRunner.js:169:2)
    at iteratePitchingLoaders (/home/vagrant/Code/CSE356/node_modules/loader-runner/lib/LoaderRunner.js:165:10)
    at /home/vagrant/Code/CSE356/node_modules/loader-runner/lib/LoaderRunner.js:173:18
    at loadLoader (/home/vagrant/Code/CSE356/node_modules/loader-runner/lib/loadLoader.js:36:3)
    at iteratePitchingLoaders (/home/vagrant/Code/CSE356/node_modules/loader-runner/lib/LoaderRunner.js:169:2)
    at iteratePitchingLoaders (/home/vagrant/Code/CSE356/node_modules/loader-runner/lib/LoaderRunner.js:165:10)
    at /home/vagrant/Code/CSE356/node_modules/loader-runner/lib/LoaderRunner.js:173:18
    at loadLoader (/home/vagrant/Code/CSE356/node_modules/loader-runner/lib/loadLoader.js:36:3)
    at iteratePitchingLoaders (/home/vagrant/Code/CSE356/node_modules/loader-runner/lib/LoaderRunner.js:169:2)
    at iteratePitchingLoaders (/home/vagrant/Code/CSE356/node_modules/loader-runner/lib/LoaderRunner.js:165:10)
    at /home/vagrant/Code/CSE356/node_modules/loader-runner/lib/LoaderRunner.js:173:18
    at loadLoader (/home/vagrant/Code/CSE356/node_modules/loader-runner/lib/loadLoader.js:36:3)
    at iteratePitchingLoaders (/home/vagrant/Code/CSE356/node_modules/loader-runner/lib/LoaderRunner.js:169:2)
    at runLoaders (/home/vagrant/Code/CSE356/node_modules/loader-runner/lib/LoaderRunner.js:362:2)
    at NormalModule.doBuild (/home/vagrant/Code/CSE356/node_modules/webpack/lib/NormalModule.js:129:2)
    at NormalModule.build (/home/vagrant/Code/CSE356/node_modules/webpack/lib/NormalModule.js:180:15)
    at Compilation.buildModule (/home/vagrant/Code/CSE356/node_modules/webpack/lib/Compilation.js:127:10)

 @ ./resources/assets/sass/app.scss 4:14-248
 @ multi ./resources/assets/js/app.js ./resources/assets/sass/app.scss

 error  in ./resources/assets/sass/app.scss

Module build failed: Error
    at /home/vagrant/Code/CSE356/node_modules/webpack/lib/NormalModule.js:141:35
    at /home/vagrant/Code/CSE356/node_modules/loader-runner/lib/LoaderRunner.js:364:11
    at /home/vagrant/Code/CSE356/node_modules/loader-runner/lib/LoaderRunner.js:170:18
    at loadLoader (/home/vagrant/Code/CSE356/node_modules/loader-runner/lib/loadLoader.js:27:11)
    at iteratePitchingLoaders (/home/vagrant/Code/CSE356/node_modules/loader-runner/lib/LoaderRunner.js:169:2)
    at iteratePitchingLoaders (/home/vagrant/Code/CSE356/node_modules/loader-runner/lib/LoaderRunner.js:165:10)
    at /home/vagrant/Code/CSE356/node_modules/loader-runner/lib/LoaderRunner.js:173:18
    at loadLoader (/home/vagrant/Code/CSE356/node_modules/loader-runner/lib/loadLoader.js:36:3)
    at iteratePitchingLoaders (/home/vagrant/Code/CSE356/node_modules/loader-runner/lib/LoaderRunner.js:169:2)
    at iteratePitchingLoaders (/home/vagrant/Code/CSE356/node_modules/loader-runner/lib/LoaderRunner.js:165:10)
    at /home/vagrant/Code/CSE356/node_modules/loader-runner/lib/LoaderRunner.js:173:18
    at loadLoader (/home/vagrant/Code/CSE356/node_modules/loader-runner/lib/loadLoader.js:36:3)
    at iteratePitchingLoaders (/home/vagrant/Code/CSE356/node_modules/loader-runner/lib/LoaderRunner.js:169:2)
    at iteratePitchingLoaders (/home/vagrant/Code/CSE356/node_modules/loader-runner/lib/LoaderRunner.js:165:10)
    at /home/vagrant/Code/CSE356/node_modules/loader-runner/lib/LoaderRunner.js:173:18
    at loadLoader (/home/vagrant/Code/CSE356/node_modules/loader-runner/lib/loadLoader.js:36:3)
    at iteratePitchingLoaders (/home/vagrant/Code/CSE356/node_modules/loader-runner/lib/LoaderRunner.js:169:2)
    at runLoaders (/home/vagrant/Code/CSE356/node_modules/loader-runner/lib/LoaderRunner.js:362:2)
    at NormalModule.doBuild (/home/vagrant/Code/CSE356/node_modules/webpack/lib/NormalModule.js:129:2)
    at NormalModule.build (/home/vagrant/Code/CSE356/node_modules/webpack/lib/NormalModule.js:180:15)
    at Compilation.buildModule (/home/vagrant/Code/CSE356/node_modules/webpack/lib/Compilation.js:127:10)
    at moduleFactory.create (/home/vagrant/Code/CSE356/node_modules/webpack/lib/Compilation.js:404:9)
    at /home/vagrant/Code/CSE356/node_modules/webpack/lib/NormalModuleFactory.js:242:4
    at /home/vagrant/Code/CSE356/node_modules/webpack/lib/NormalModuleFactory.js:93:13
    at /home/vagrant/Code/CSE356/node_modules/tapable/lib/Tapable.js:204:11
    at NormalModuleFactory.<anonymous> (/home/vagrant/Code/CSE356/node_modules/webpack/lib/CompatibilityPlugin.js:51:4)
    at NormalModuleFactory.applyPluginsAsyncWaterfall (/home/vagrant/Code/CSE356/node_modules/tapable/lib/Tapable.js:208:13)
    at onDoneResolving (/home/vagrant/Code/CSE356/node_modules/webpack/lib/NormalModuleFactory.js:68:11)
    at onDoneResolving (/home/vagrant/Code/CSE356/node_modules/webpack/lib/NormalModuleFactory.js:189:6)
    at _combinedTickCallback (internal/process/next_tick.js:67:7)

 error

/home/vagrant/Code/CSE356/node_modules/extract-text-webpack-plugin/loader.js?{"id":1,"omit":1,"remove":true}!/home/vagrant/Code/CSE356/node_modules/style-loader/index.js!/home/vagrant/Code/CSE356/node_modules/css-loader/index.js!/home/vagrant/Code/CSE356/node_modules/postcss-loader/index.js!/home/vagrant/Code/CSE356/node_modules/resolve-url-loader/index.js!/home/vagrant/Code/CSE356/node_modules/sass-loader/index.js?sourceMap&precision=8!/home/vagrant/Code/CSE356/resources/assets/sass/app.scss doesn't export content
                                                                                                   Asset      Size  Chunks                    Chunk Names
       /js/app.js   1.16 MB       0  [emitted]  [big]  /js/app
mix-manifest.json  32 bytes          [emitted]

npm ERR! Linux 4.4.0-51-generic
npm ERR! argv "/usr/local/bin/node" "/usr/bin/npm" "run" "dev"
npm ERR! node v7.4.0
npm ERR! npm  v4.1.2
npm ERR! code ELIFECYCLE
npm ERR! @ dev: `node node_modules/cross-env/bin/cross-env.js 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 2
npm ERR!
npm ERR! Failed at the @ dev script 'node node_modules/cross-env/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the  package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node node_modules/cross-env/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/vagrant/Code/CSE356/npm-debug.log
vagrant@homestead:~/Code/CSE356$

I have not modified the original package.json or webpack.mix.js files.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 15

Most upvoted comments

It should install node-sass for you automatically, but if it failed for some reason, do:

npm install node-sass

To other people with similar issues, maybe this can help:

I had an issue when running npm install node-sass

So I ran npm install node-sass --no-bin-links and had no issues. Then I was able to run npm run dev with no issues.

Thanks for the help Jeffrey!

I solved the issue by deleting the package-lock.json file, the node_modules folder and npm install

$ rm package-lock.json
$ rm -rf node_modules
$ npm install

write these npm install style-loader css-loader autoprefixer-loader sass-loader node-sass --save-dev

Try running

npm cache verify

Before running

npm install

Then see if that takes care of your issue.

copy node-sass folder from any other node_modules and npm install. It works for me.

Senhores, só para ver se agrega ai para voces. Depois de executar os comandos abaixo FUNCIONOU! Usando Ubuntu

sudo -s
sudo npm cache verify
sudo rm package-lock.json
sudo rm -rf node_modules
sudo npm install
sudo npm install node-sass

npm install node-sass.