52

I am trying to install node-sass in a project, which perfectly builds and runs on my pc but on my surface I am having major issues when trying to install the packages.

Note: I have tryed reinstalling and rebuilding the project several times.

Summary of the error:

gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:\Users\Max-T\Documents\Sources\StaffMangerV2\black-dashboard-pro-react-v1.0.0\node_modules\node-gyp\lib\build.js:262:23)
gyp ERR! stack     at ChildProcess.emit (events.js:210:5)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
gyp ERR! System Windows_NT 10.0.18362
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\Max-T\\Documents\\Sources\\StaffMangerV2\\black-dashboard-pro-react-v1.0.0\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd C:\Users\Max-T\Documents\Sources\StaffMangerV2\black-dashboard-pro-react-v1.0.0\node_modules\node-sass
gyp ERR! node -v v12.13.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
Build failed with error code: 1
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules\react-scripts\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-sass@4.11.0 postinstall: `node scripts/build.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-sass@4.11.0 postinstall 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!     C:\Users\Max-T\AppData\Roaming\npm-cache\_logs\2019-10-30T10_05_01_386Z-debug.log

package.json => https://hastebin.com/azetegukes.pl too much coode so I had to paste it elsewhere.

Maxdola
  • 1,562
  • 2
  • 10
  • 29
  • Have you tried using yarn ? For most of the times yarn solved my problem for this. – Rehan Sattar Oct 30 '19 at 10:19
  • Have you checked your npm config file? Is it correct because sometimes it gets corrupt and cause such issues. You can run npm run --config – Mohit Oct 30 '19 at 10:21
  • @Mohit Tryed that, but the output seems fine to me => [hastebin](https://hastebin.com/xojopitugi.sql) – Maxdola Oct 30 '19 at 17:53
  • @RehanSattar Also tryed that before and now again, with a complete error log => [hastebin](https://hastebin.com/zevahuxoyo.makefile) – Maxdola Oct 30 '19 at 17:57
  • 3
    USE `NODE VERSION 10`, it will work, TO USE MULTIPLE NODE VERSION ON SAME PC,YOU CAN USE `NVM` – Parth Developer Dec 22 '21 at 07:05

7 Answers7

46

You're using Node 12, and node-sass needs to be at least 4.12 to support that version https://github.com/sass/node-sass#node-version-support-policy

nschonni
  • 4,069
  • 1
  • 28
  • 37
  • Thanks, that actually fixed the installation bug, but I am still ending up with the same error in the browser => [hastebin](https://hastebin.com/inatoregex.cs) – Maxdola Oct 31 '19 at 08:23
  • 1
    That looks like a separate question – nschonni Oct 31 '19 at 14:09
  • actually true ... so I will ask a new one. – Maxdola Oct 31 '19 at 16:23
  • 9
    It's worth mentioning that each Node version has a specific required node-sass version, more info here: https://github.com/sass/node-sass#node-version-support-policy – Piotr Jaworski May 12 '21 at 21:35
  • Also worth mentioning the [node version manager](https://github.com/coreybutler/nvm-windows) so you can quickly switch between node versions to run legacy projects! – adamdport May 18 '22 at 16:20
  • @adamdport Thanks! `nvm` is a cool tool to quickly switch between different npm and node versions without messing things up. – Sohail Saha Jul 18 '22 at 06:45
23

If anyone runs into this lately... the easiest fix is to replace node-sass with just sass in your dependencies. It's the more recently maintained version and I only had to change 1 line of code with how it's initialized and all of my existing code was already compatible.

There are more details at https://sass-lang.com/blog/libsass-is-deprecated under How to migrate.

Matt Toigo
  • 659
  • 1
  • 6
  • 6
16

Don't use node-sass anymore

node-sass is deprecated. Instead use the new version which is sass.

You can uninstall the old and install the new one with this command

npm uninstall node-sass
npm install sass


Abraham
  • 12,140
  • 4
  • 56
  • 92
  • 1
    Totally agree. I used node-sass with laravel-mix, but now node-sass isn't in list of required dependencies. – Vlad Aug 23 '22 at 18:40
  • 1
    Finally. I always struggled with it because of `node-gyp` build errors on windows and in alpine linux build containers. Until now the solution was to use node14 and python2 and vs-2017 build tools on windows. There are many resources what to do in case of errors but none gave the hint to replace it. thanks mate! – Jürgen Steinblock Feb 17 '23 at 10:41
7

try this command it works for me

sudo npm install -g --unsafe-perm node-sass
3

After more than 2 hours of trying all sorts of ways (cleaning npm cache, deleting node_modules, trying to install with global switch -g, etc.) to install node-sass and failing every time, I finally changed the mirror to china and it immediately worked for me!! (I know it kinda doesn't make any sense, considering the error I was getting)

Just for reference, this was the error I was receiving before it finally worked:

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-sass@4.14.0 postinstall: `node scripts/build.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-sass@4.14.0 postinstall 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!     C:\Users\****\AppData\Roaming\npm-cache\_logs\2020-06-06T13_56_56_768Z-debug.log

My Node version: v12.18.0
node-sass version in package.json: "^4.14.0"

I changed the mirror as stated in the node-sass npm page.

npm install -g mirror-config-china --registry=http://registry.npm.taobao.org
npm install node-sass

Hope that helps.

Sнаđошƒаӽ
  • 16,753
  • 12
  • 73
  • 90
1

Here are steps fro replacing node-sass with sass which resolved my exact issue:

  1. First remove 'node-sass'. Go to your package.json (remove it from dependency)
  2. Than, remove package-lock.json file and node_modules
  3. npm install
  4. npm install sass --save

'npm start' would be your next step

StefaDesign
  • 929
  • 10
  • 19
0

The best option would probably be to replace node-sass lib with sass one. But in our case I fixed that by installing nvm and setting local node version to 14.17.6 My node-sass version is 4.14.1

Aliaksei
  • 1,094
  • 11
  • 20