Can't install 'node-sass' on Ubuntu 20

10,065

Solution 1

Run this commands: rm -rf ./node_modules ./package-lock.json, then npm cache verify. PS: I recommend to install nvm

$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash

Also I don’t know if you already have it, but make sure to also have build-essential install

$ sudo apt update && apt install build-essential 

It is a set of c++ compilers and Bunch of useful 💩

something else that I have seen is the lack of python 2.x.x

$ sudo apt install python

Solution 2

Try this, it worked for me

npm i --unsafe-perm node-sass
Share:
10,065
gorevanova
Author by

gorevanova

Updated on July 18, 2022

Comments

  • gorevanova
    gorevanova almost 2 years

    I use webpack 4, sass, pug and bemto. Module on windows worked normal, but on Ubuntu:

    npm ERR! code ELIFECYCLE
    npm ERR! syscall spawn
    npm ERR! file sh
    npm ERR! errno ENOENT
    npm ERR! [email protected] postinstall: `node scripts/build.js`
    npm ERR! spawn ENOENT
    npm ERR! 
    npm ERR! Failed at the [email protected] postinstall script.
    npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
    

    I tried enter command:

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

    >

    (node:8310) [DEP0139] DeprecationWarning: Calling process.umask() with no arguments is prone to race conditions and is a potential security vulnerability.
    (Use `node --trace-deprecation ...` to show where the warning was created)
    npm WARN deprecated [email protected]: request has been deprecated, see https://github.com/request/request/issues/3142
    /usr/local/bin/node-sass -> /usr/local/lib/node_modules/node-sass/bin/node-sass
    npm WARN lifecycle The node binary used for scripts is /snap/bin/node but npm is using /snap/node/2725/bin/node itself. Use the `--scripts-prepend-node-path` option to include the path for the node binary npm was executed with.
    
    > [email protected] install /usr/local/lib/node_modules/node-sass
    > node scripts/install.js
    
    Cached binary found at /root/.npm/node-sass/4.14.1/linux-x64-83_binding.node
    
    > [email protected] postinstall /usr/local/lib/node_modules/node-sass
    > node scripts/build.js
    
    Binary found at /usr/local/lib/node_modules/node-sass/vendor/linux-x64-83/binding.node
    Testing binary
    /snap/node/2725/bin/node: symbol lookup error: /usr/local/lib/node_modules/node-sass/vendor/linux-x64-83/binding.node: undefined symbol: _ZN2v816FunctionTemplate3NewEPNS_7IsolateEPFvRKNS_20FunctionCallbackInfoINS_5ValueEEEENS_5LocalIS4_EENSA_INS_9SignatureEEEiNS_19ConstructorBehaviorENS_14SideEffectTypeEPKNS_9CFunctionE
    npm WARN You are using a pre-release version of node and things may not work as expected
    
    npm ERR! code ELIFECYCLE
    npm ERR! syscall spawn
    npm ERR! file sh
    npm ERR! errno ENOENT
    npm ERR! [email protected] postinstall: `node scripts/build.js`
    npm ERR! spawn ENOENT
    npm ERR! 
    npm ERR! Failed at the [email protected] postinstall script.
    npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
    

    UPD:

    I tried: npm uninstall node-sass After: npm install node-sass Did not help.

    I tried: npm install node-gyp global, save, savedev

    ERROR in ./src/sсss/critical.scss (./node_modules/css-loader??ref--5-1!./node_modules/sass-loader/lib/loader.js??ref--5-2!./src/sсss/critical.scss)
    Module build failed (from ./node_modules/sass-loader/lib/loader.js):
    Error: Cannot find module 'node-sass'
    Require stack:
    - /home/gorevanova/Documents/WebStorm/webpack-static/node_modules/sass-loader/lib/loader.js
    - /home/gorevanova/Documents/WebStorm/webpack-static/node_modules/loader-runner/lib/loadLoader.js
    - /home/gorevanova/Documents/WebStorm/webpack-static/node_modules/loader-runner/lib/LoaderRunner.js
    - /home/gorevanova/Documents/WebStorm/webpack-static/node_modules/webpack/lib/NormalModule.js
    - /home/gorevanova/Documents/WebStorm/webpack-static/node_modules/webpack/lib/NormalModuleFactory.js
    - /home/gorevanova/Documents/WebStorm/webpack-static/node_modules/webpack/lib/Compiler.js
    - /home/gorevanova/Documents/WebStorm/webpack-static/node_modules/webpack/lib/webpack.js
    - /home/gorevanova/Documents/WebStorm/webpack-static/node_modules/webpack-dev-server/bin/webpack-dev-server.js
        at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1020:15)
        at Function.Module._load (internal/modules/cjs/loader.js:890:27)
        at Module.require (internal/modules/cjs/loader.js:1080:19)
        at require (internal/modules/cjs/helpers.js:72:18)
        at Object.<anonymous> (/home/gorevanova/Documents/WebStorm/webpack-static/node_modules/sass-loader/lib/loader.js:3:14)
        at Module._compile (internal/modules/cjs/loader.js:1176:30)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:1196:10)
        at Module.load (internal/modules/cjs/loader.js:1040:32)
        at Function.Module._load (internal/modules/cjs/loader.js:929:14)
        at Module.require (internal/modules/cjs/loader.js:1080:19)
        at require (internal/modules/cjs/helpers.js:72:18)
        at loadLoader (/home/gorevanova/Documents/WebStorm/webpack-static/node_modules/loader-runner/lib/loadLoader.js:18:17)
        at iteratePitchingLoaders (/home/gorevanova/Documents/WebStorm/webpack-static/node_modules/loader-runner/lib/LoaderRunner.js:169:2)
        at iteratePitchingLoaders (/home/gorevanova/Documents/WebStorm/webpack-static/node_modules/loader-runner/lib/LoaderRunner.js:165:10)
        at /home/gorevanova/Documents/WebStorm/webpack-static/node_modules/loader-runner/lib/LoaderRunner.js:176:18
        at loadLoader (/home/gorevanova/Documents/WebStorm/webpack-static/node_modules/loader-runner/lib/loadLoader.js:47:3)
    

    But problem don't leave me.

  • gorevanova
    gorevanova about 4 years
    I tried to clear the cache, despite system warnings. Did not help.
  • gorevanova
    gorevanova about 4 years
    npm uninstall node-sass. After: npm install node-sass. Did not help.
  • Ernesto
    Ernesto about 4 years
    you did everything except one thing npm WARN You are using a pre-release version of node and things may not work as expected Also this ``` pm WARN lifecycle The node binary used for scripts is /snap/bin/node but npm is using /snap/node/2725/bin/node itself. ``` it is telling you that the node version use to compile the snap for node-sass is not compatible with the current version. That's why I mentioned nvm github.com/nvm-sh/nvm
  • Lukman Isiaka
    Lukman Isiaka almost 3 years
    Installing Python fixed the error for me on Ubuntu 20.14