'Error with node-sass when running npm install

I'm getting the following errors whenever I run npm install on a vue.js project

5769 error code 1
5770 error path /*my path*/node_modules/node-sass
5771 error command failed
5772 error command sh -c node scripts/install.js
5773 error /*my path*/node_modules/request/index.js:30
5773 error   if (options !== null && typeof op
5773 error
5773 error
5773 error SyntaxError: Unexpected end of input
5773 error     at Object.compileFunction (node:vm:352:18)
5773 error     at wrapSafe (node:internal/modules/cjs/loader:1031:15)
5773 error     at Module._compile (node:internal/modules/cjs/loader:1065:27)
5773 error     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
5773 error     at Module.load (node:internal/modules/cjs/loader:981:32)
5773 error     at Function.Module._load (node:internal/modules/cjs/loader:822:12)
5773 error     at Module.require (node:internal/modules/cjs/loader:1005:19)
5773 error     at require (node:internal/modules/cjs/helpers:102:18)
5773 error     at Object.<anonymous> (/*my path*/node_modules/node-sass/scripts/install.js:10:13)
5773 error     at Module._compile (node:internal/modules/cjs/loader:1101:14)
5774 verbose exit 1

I've tried reinstalling node and npm, but it always seems to stop on node-sass. npm install runs just fine on all my laravel projects. This only happens on the two projects that I've pulled recently that almost entirely Vue.js and typescript so I'm not sure if that may be the issue.

Edit: I tried delete my local version, pull from github and run npm install again and got this error. It was a bit of a mammoth error so I've had to delet a big chunk of it to fit it into the post.

2863 error code 1
2864 error path /*my path*/node_modules/node-sass
2865 error command failed
2866 error command sh -c node scripts/build.js
2867 error Building: /opt/homebrew/Cellar/node/16.10.0/bin/node /Users/scott/Dev/KPro/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
2867 error   c++ '-DNODE_GYP_MODULE_NAME=libsass' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-DV8_DEPRECATION_WARNINGS' '-DV8_IMMINENT_DEPRECATION_WARNINGS' '-D_GLIBCXX_USE_CXX11_ABI=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DLIBSASS_VERSION="3.5.5"' -I/Users/scott/.node-gyp/16.10.0/include/node -I/Users/scott/.node-gyp/16.10.0/src -I/Users/scott/.node-gyp/16.10.0/deps/openssl/config -I/Users/scott/.node-gyp/16.10.0/deps/openssl/openssl/include -I/Users/scott/.node-gyp/16.10.0/deps/uv/include -I/Users/scott/.node-gyp/16.10.0/deps/zlib -I/Users/scott/.node-gyp/16.10.0/deps/v8/include -I../src/libsass/include  -O3 -gdwarf-2 -mmacosx-version-min=10.7 -arch arm64 -Wall -Wendif-labels -W -Wno-unused-parameter -std=c++11 -stdlib=libc++ -fno-strict-aliasing -MMD -MF ./Release/.deps/Release/obj.target/libsass/src/libsass/src/ast.o.d.raw   -c -o Release/obj.target/libsass/src/libsass/src/ast.o ../src/libsass/src/ast.cpp
2867 error   c++ '-DNODE_GYP_MODULE_NAME=libsass' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-DV8_DEPRECATION_WARNINGS' '-DV8_IMMINENT_DEPRECATION_WARNINGS' '-D_GLIBCXX_USE_CXX11_ABI=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DLIBSASS_VERSION="3.5.5"' -I/Users/scott/.node-gyp/16.10.0/include/node -I/Users/scott/.node-gyp/16.10.0/src -I/Users/scott/.node-gyp/16.10.0/deps/openssl/config -I/Users/scott/.node-gyp/16.10.0/deps/openssl/openssl/include -I/Users/scott/.node-gyp/16.10.0/deps/uv/include -I/Users/scott/.node-gyp/16.10.0/deps/zlib -I/Users/scott/.node-gyp/16.10.0/deps/v8/include -I../src/libsass/include  -O3 -gdwarf-2 -mmacosx-version-min=10.7 -arch arm64 -Wall -Wendif-labels -W -Wno-unused-parameter -std=c++11 -stdlib=libc++ -fno-strict-aliasing -MMD -MF ./Release/.deps/Release/obj.target/libsass/src/libsass/src/ast_fwd_decl.o.d.raw   -c -o Release/obj.target/libsass/src/libsass/src/ast_fwd_decl.o ../src/libsass/src/ast_fwd_decl.cpp

2868 error gyp info it worked if it ends with ok
2868 error gyp verb cli [
2868 error gyp verb cli   '/opt/homebrew/Cellar/node/16.10.0/bin/node',
2868 error gyp verb cli   '/*my path*/node_modules/node-gyp/bin/node-gyp.js',
2868 error gyp verb cli   'rebuild',
2868 error gyp verb cli   '--verbose',
2868 error gyp verb cli   '--libsass_ext=',
2868 error gyp verb cli   '--libsass_cflags=',
2868 error gyp verb cli   '--libsass_ldflags=',
2868 error gyp verb cli   '--libsass_library='
2868 error gyp verb cli ]
2868 error gyp info using [email protected]
2868 error gyp info using [email protected] | darwin | arm64
2868 error gyp verb command rebuild []
2868 error gyp verb command clean []
2868 error gyp verb clean removing "build" directory
2868 error gyp verb command configure []
2868 error gyp verb check python checking for Python executable "python2" in the PATH
2868 error gyp verb `which` succeeded python2 /usr/bin/python2
2868 error gyp verb check python version `/usr/bin/python2 -c "import sys; print "2.7.16
2868 error gyp verb check python version .%s.%s" % sys.version_info[:3];"` returned: %j
2868 error gyp verb get node dir no --target version specified, falling back to host node version: 16.10.0
2868 error gyp verb command install [ '16.10.0' ]
2868 error gyp verb install input version string "16.10.0"
2868 error gyp verb install installing version: 16.10.0
2868 error gyp verb install --ensure was passed, so won't reinstall if already installed
2868 error gyp verb install version is already installed, need to check "installVersion"
2868 error gyp verb got "installVersion" 9
2868 error gyp verb needs "installVersion" 9
2868 error gyp verb install version is good
2868 error gyp verb get node dir target node version installed: 16.10.0
2868 error gyp verb build dir attempting to create "build" dir: /Users/scott/Dev/KPro/node_modules/node-sass/build
2868 error gyp verb build dir "build" dir needed to be created? /Users/scott/Dev/KPro/node_modules/node-sass/build
2868 error gyp verb build/config.gypi creating config file
2868 error gyp verb build/config.gypi writing out config file: /*my path*/node_modules/node-sass/build/config.gypi
2868 error (node:57324) [DEP0150] DeprecationWarning: Setting process.config is deprecated. In the future the property will be read-only.
2868 error (Use `node --trace-deprecation ...` to show where the warning was created)
2868 error gyp verb config.gypi checking for gypi file: /*my path*/node_modules/node-sass/config.gypi
2868 error gyp verb common.gypi checking for gypi file: /*my path*/node_modules/node-sass/common.gypi
2868 error gyp verb gyp gyp format was not specified; forcing "make"
2868 error gyp info spawn /usr/bin/python2
2868 error gyp info spawn args [
2868 error gyp info spawn args   '/*my path*/node_modules/node-gyp/gyp/gyp_main.py',
2868 error gyp info spawn args   'binding.gyp',
2868 error gyp info spawn args   '-f',
2868 error gyp info spawn args   'make',
2868 error gyp info spawn args   '-I',
2868 error gyp info spawn args   '/*my path*/node_modules/node-sass/build/config.gypi',
2868 error gyp info spawn args   '-I',
2868 error gyp info spawn args   '/*my path*/node_modules/node-gyp/addon.gypi',
2868 error gyp info spawn args   '-I',
2868 error gyp info spawn args   '/Users/scott/.node-gyp/16.10.0/include/node/common.gypi',
2868 error gyp info spawn args   '-Dlibrary=shared_library',
2868 error gyp info spawn args   '-Dvisibility=default',
2868 error gyp info spawn args   '-Dnode_root_dir=/Users/scott/.node-gyp/16.10.0',
2868 error gyp info spawn args   '-Dnode_gyp_dir=/Users/scott/Dev/KPro/node_modules/node-gyp',
2868 error gyp info spawn args   '-Dnode_lib_file=/Users/scott/.node-gyp/16.10.0/<(target_arch)/node.lib',
2868 error gyp info spawn args   '-Dmodule_root_dir=/*my path*/node_modules/node-sass',
2868 error gyp info spawn args   '-Dnode_engine=v8',
2868 error gyp info spawn args   '--depth=.',
2868 error gyp info spawn args   '--no-parallel',
2868 error gyp info spawn args   '--generator-output',
2868 error gyp info spawn args   'build',
2868 error gyp info spawn args   '-Goutput_dir=.'
2868 error gyp info spawn args ]
2868 error gyp verb command build []
2868 error gyp verb build type Release
2868 error gyp verb architecture arm64
2868 error gyp verb node dev dir /Users/scott/.node-gyp/16.10.0
2868 error gyp verb `which` succeeded for `make` /usr/bin/make
2868 error gyp info spawn make
2868 error gyp info spawn args [ 'V=1', 'BUILDTYPE=Release', '-C', 'build' ]

2868 error 2 warnings generated.
2868 error In file included from ../src/libsass/src/ast_fwd_decl.cpp:1:
2868 error ../src/libsass/src/ast.hpp:1614:25: warning: loop variable 'numerator' creates a copy from type 'const std::__1::basic_string<char>' [-Wrange-loop-construct]
2868 error         for (const auto numerator : numerators)
2868 error                         ^
2868 error ../src/libsass/src/ast.hpp:1614:14: note: use reference type 'const std::__1::basic_string<char> &' to prevent copying
2868 error         for (const auto numerator : numerators)
2868 error              ^~~~~~~~~~~~~~~~~~~~~~
2868 error                         &
2868 error ../src/libsass/src/ast.hpp:1616:25: warning: loop variable 'denominator' creates a copy from type 'const std::__1::basic_string<char>' [-Wrange-loop-construct]
2868 error         for (const auto denominator : denominators)
2868 error                         ^
2868 error ../src/libsass/src/ast.hpp:1616:14: note: use reference type 'const std::__1::basic_string<char> &' to prevent copying
2868 error         for (const auto denominator : denominators)
2868 error              ^~~~~~~~~~~~~~~~~~~~~~~~



2868 error                                      remove_cv
2868 error /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/type_traits:776:50: note: 'remove_cv' declared here
2868 error template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_cv
2868 error                                                  ^
2868 error 1 error generated.
2868 error make: *** [Release/obj.target/binding/src/binding.o] Error 1
2868 error gyp ERR! build error
2868 error gyp ERR! stack Error: `make` failed with exit code: 2
2868 error gyp ERR! stack     at ChildProcess.onExit (/*my path*/node_modules/node-gyp/lib/build.js:262:23)
2868 error gyp ERR! stack     at ChildProcess.emit (node:events:390:28)
2868 error gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12)
2868 error gyp ERR! System Darwin 20.6.0
2868 error gyp ERR! command "/opt/homebrew/Cellar/node/16.10.0/bin/node" "/*my path*/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
2868 error gyp ERR! cwd /*my path*/node_modules/node-sass
2868 error gyp ERR! node -v v16.10.0
2868 error gyp ERR! node-gyp -v v3.8.0
2868 error gyp ERR! not ok
2868 error Build failed with error code: 1
2869 verbose exit 1


Solution 1:[1]

If you're using Node 16, change node-sass to versions >= 6.0.1, then reinstalling the dependencies by npm i may fixed your problem. See the tracking issue https://github.com/sass/node-sass/issues/3077.

If failed, you may need to:

rm -rf node_modules package-lock.json 
npm cache clean --force
npm i

Solution 2:[2]

node-sass has been deprecated.

It has been transformed to the npm package sass now.

You can uninstall the old and install the new one

npm uninstall node-sass

npm install sass

Many issues also those during installation have been fixed with this.


Solution 3:[3]

I fixed this by adding these to my devDependencies in package.json:

"node-pre-gyp": "0.17.0",
"fsevents": "2.2.1"

Found in https://github.com/nodejs/node-gyp/issues/2296

Solution 4:[4]

Make sure that "sass-loader" in your "devDependencies" (or in "dependencies") is not an old version. For me, i had to uninstall "sass-loader" (an old version), and then install "node-sass" and finally "sass-loader" (without forcing any version).

Solution 5:[5]

None of that worked for me, the only thing that worked was going to an earlier build of npm.

sudo npm install -g n
sudo n 12
npm install

Apparently, the version of assets I was trying to install were too old to work with a current version of npm so downgrading to an earlier version was all that was needed to successfully install.

Now I can work on upgrading things to the latest versions.

Solution 6:[6]

Check the version of node-sass plugin in the package.json file. In my case, it was 4.10.0, and as per the release docs of this version, it supports node version 11, and mine was 16. So either you update the plugin version so that it is compatible with node 16, or you downgrade your node version, so that node becomes compatible with your plugin version.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jinbo
Solution 2 Dharman
Solution 3 Todd Hale
Solution 4 Dali
Solution 5 elegasoft
Solution 6 Sandeep Poonia