npm install throwing error in node-sass - node.js

node-sass#2.1.1 install /home/user/Documents/project/node_modules/node-sass
> node scripts/install.js
WARN invalid config loglevel="notice"
Can not download file from https://raw.githubusercontent.com/sass/node-sass-binaries/v2.1.1/linux-x64-node-8.2/binding.node
> node-sass#2.1.1 postinstall /home/user/Documents/project/node_modules/node-sass
> node scripts/build.js
module.js:487
throw err;
^
Error: Cannot find module '/home/user/Documents/project/node_modules/node-sass/node_modules/pangyp/bin/node-gyp'
at Function.Module._resolveFilename (module.js:485:15)
at Function.Module._load (module.js:437:25)
at Function.Module.runMain (module.js:605:10)
at startup (bootstrap_node.js:158:16)
at bootstrap_node.js:575:3
Build failed
added 2186 packages in 42.166s
I tried so far:
npm rebuild
npm rebuild node-sass
npm uninstall -g node-sass
rm -rf node_module

Replace node-sass with sass, which is a pure-JS implementation and is less prone to build errors as it doesn't use node-gyp.
npm uninstall node-sass
npm i -D sass
It can then be added to package.json as follows, for example:
{
"scripts": {
"build:css": "sass --style compressed --update src/scss:static/css",
"watch:css": "sass --watch src/scss:static/css",
}
}

You need to do next steps and it should work:
rm -rf node_modules package-lock.json
npm install --saveDev node-sass#4.5.3
npm install
Voila :)

by using yarn run:
yarn add node-sass

Removed package-lock.json, installed Python 2.7, added an env variable for python path.
Ran npm install.
Voila !

node-sass has minimum dependency according to the version of node installed in your system. You can find out the minimum version required here

Use
Node : v14.16.0
node-sass: ^4.14.1
it works for me

This question is old, but if you arrive here in 2022 or later, then this info may be useful:
node-sass is deprecated. Now you should use sass.
That's why the answer given by Usama Muhammad works. Hope this helps.
Sources:
https://www.npmjs.com/package/node-sass
https://www.npmjs.com/package/dart-sass

The minimum version with Node 8 support is 4.5.3. Offhand, I don't think 2.x will support anything above Node 0.12, which is EOL.

Delete package-lock.json
Remove 'node-sass' dependency from your package.json
run npm install
run npm gulp-sass --save-dev
run npm i -d sass
run npm start

I have found I get node-sass errors when trying to install over a corporate proxy. The first solution is to ensure your .npmrc file has proxy allowance.
.npmrc
# Try removing reference to registry, as sometimes your local corporate registry of node_modules may not include node-sass
# // registry=https://....
# note if using special characters in pass, encode them: eg: h#ppy = h%40ppy
strict-ssl=false
proxy=http://<username>:<pass>#proxyhost:<port>
https-proxy=http://<uname>:<pass>#proxyhost:<port>
NODE_TLS_REJECT_UNAUTHORIZED = 0
Then in command line before running any install
set NODE_TLS_REJECT_UNAUTHORIZED = 0
Zip node-binding files from node-sass github site in order to download them over corporate network.
Example:
https://github.com/inspiraller/node-sass-bindings

Add manually in package.json : "node-sass": "4.13.0"
and update package.json in terminal npm install

Related

Vue2 - Error: PostCSS received undefined instead of CSS string

i have this problem when trying to compile a Vue2 project
Syntax Error: Error: PostCSS received undefined instead of CSS string
# ./src/assets/sass/main.scss 4:14-233 14:3-18:5 15:22-241
# ./src/main.js
# multi (webpack)-dev-server/client?http://192.168.1.202:8080&sockPath=/sockjs-node (webpack)/hot/dev-server.js ./src/main.js
I have tried to rebuild the sass-loader with no success.
My node version is v16.6.1
My NPM version is 7.21.0
Webpack is 5.1.2 and the sass-loader version is 10.2.0
This is a VUE2 project and all started when i started a new Vue3 project and i had to upgrade the vue/cli but i cannot understand how to go back locally (if this is the problem)
Try it
npm install node-sass
or
npm rebuild node-sass
I got answer for here
Solved by first uninstalling node-sass:
yarn remove node-sass
And then installing sass instead:
yarn add -D sass
I also faced the same error and after downgrading the node version it was fixed.
I resolved this issue by downgrading my version of "node-sass" to "^4.14.1":
npm install node-sass#4.14.1
solved by switching to node v15.14.0
Hey, I was following a tutorial about VueJS, and I had the same error, tried to rebuild node-sass it didn't work.
Then I saw that the lang used in the style balise was SCSS (in the App.vue) , I changed it to CSS and it worked. :)
This error, Error: PostCSS received undefined instead of CSS string is being thrown by sass-loader.
One solution would be to reinstall sass-loader. By using the following steps, the sass compile error should be fixed.
Steps for npm & yarn
! Note: If you have node-sass installed, you will need to reinstall it as well, by using the following commands:
# npm
npm uninstall sass-loader node-sass
npm install sass-loader node-sass --save-dev
# yarn
yarn remove sass-loader node-sass
yarn add sass-loader node-sass --dev
To reinstall sass-loader run these commands:
# npm
npm uninstall sass-loader
npm install sass-loader --save-dev
# yarn
yarn remove sass-loader
yarn add sass-loader --dev

Need to install 'webpack-dev-server'

I have cloned a repo from GitHub for a project. I've already installed node (-v 14.17.5) and npm (-v7.20.6), however when I run npm start I get the following code. I've tried reinstalling node and npm several times but I keep getting the same error:
$ npm start
> simplefolio#1.0.1 start
> webpack server --config webpack.dev.js --open
[webpack-cli] You need to install 'webpack-dev-server' for running 'webpack serve'.
Error: Cannot find module 'webpack-dev-server/bin/cli-flags'
Require stack:
- C:\Users\edwin\Desktop\git\simplefolio\node_modules\#webpack-cli\serve\lib\index.js
- C:\Users\edwin\Desktop\git\simplefolio\node_modules\webpack-cli\lib\webpack-cli.js
- C:\Users\edwin\Desktop\git\simplefolio\node_modules\webpack-cli\lib\bootstrap.js
- C:\Users\edwin\Desktop\git\simplefolio\node_modules\webpack-cli\bin\cli.js
- C:\Users\edwin\Desktop\git\simplefolio\node_modules\webpack\bin\webpack.js
Remove node_modules and package-lock.json, then npm i again
Remove node modules, then npm i again
In my case, I have node 16.13.0 and npm 7.20.1. Removing nodes_modules, package-lock.json and run npm cache clean --force alone didn't help. The key change for me is upgrading npm version to the latest (8.7.0), then combining with clean install.

How to uninstall global package with npm?

I have installed webpack in this way:
npm install -g webpack
Now want to uninstall it:
npm uninstall -g webpack
Check it again, it didn't been uninstalled:
webpack -v
3.1.0
Why?
And, I use this way can't find webpack:
npm list -g | grep webpack
This also didn't work:
npm uninstall -g webpack --save
After run this under a directory which included package.json:
npm uninstall webpack
npm WARN babel-loader#6.4.1 requires a peer of webpack#1 || 2 || ^2.1.0-beta || ^2.2.0-rc but none was installed.
npm WARN uglifyjs-webpack-plugin#0.3.1 requires a peer of uglify-js#^2.8.0 but none was installed.
npm WARN uglifyjs-webpack-plugin#0.3.1 requires a peer of webpack#^1.9 || ^2 || ^2.1.0-beta || ^2.2.0-rc but none was installed.
Try running both of the below commands:
npm uninstall -g webpack
npm uninstall webpack
I think you might be checking/looking at the local version after deleting only the global one.
You have to remove the packages manually installed globally on your os with sudo:
On OsX navigate to this directory
cd /usr/local/lib/node_modules
and
sudo rm -rf <packageName> // sudo rm -rf webpack
npm uninstall -g webpack
Worked for me, try running the command prompt in administrator mode.
You're most likely running a file from another install of npm.
Run which webpack to see where your shell is finding webpack.
Run npm root -g to find the root of the tree it's supposed to be in, being sure you're running the correct npm with npm -v and which npm.
If your webpack bin isn't in the npm root, reset your path to the webpack binary e.g. hash -d webpack in bash, and then go remove the unwanted npm root from your PATH variable. You can now use npm install -g webpack and npm uninstall -g webpack and it should work.
I have tried uninstalling global packages in several ways.
npm uninstall -g <package_name> this didn't work.
I managed to remove the global packages in the following way:
Goto terminal
Run this command npm list -g
Goto the path (C:\Users\user\AppData\Roaming\npm)
Delete all the related files to your package
Goto node_modules find and delete the package
This should work.
YW!
If you are using Node Version Manager (nvm) and you want to remove a global system package you will need to switch to that version. For example:
nvm use system
npm uninstall -g webpack
Try
chown -R "$(whoami)": "$(npm root -g)"
(you may need sudo for it) and then npm uninstall -g again
on windows run as administrator and run the command
npm uninstall -g webpack
on Linux
sudo npm uninstall -g webpack
In Windows, open the cmd with Administrator rights (start -> type cmd -> right-click on icon -> open with adm. rights), then navigate (in cmd type "cd ../../users/your_user_name") to your user folder, then run
npm uninstall -g webpack
or (I don't remember which one worked for me)
npm uninstall webpack
Had the same issue an none of the answer above helped.
My project was in a sub-directory of a larger project, which also had a node_modules folder.
That's why it says, something like "found another version higher in the tree."
Delete that folder, go back to your sub-dir, remove node_modules and package-lock.json, and finally run npm install again.
In archlinux, after running
npm uninstall -g <package_name>
you might have to manually enter /usr/lib/node_modules/ to remove the package's directory. This will prevent conflicts if you try reinstalling that package with a different package manager like pacman.
Building on #karthik006 's answer of deleting directly from the global node_module folder, if you are using nvm, you first need to decide from which version of node you want to delete the global package.
After that, switch to that version of node using nvm use <version>
Then run nvm which current to get the path where the executable for this version of node is saved.
The path will be something like <path to nvm node dir>/<node version>/bin/node
Using this path, cd into <path to nvm node dir>/<node version>/lib/node_modules and then rm -rf the packages that you want to remove.
On ubuntu the package I was on the hunt for was buried in ~/.npm/_npx/<chars>/node_modules/ and in ~/.npm/_npx/<chars>/node_modules/.bin/. I removed the bin and the directory and got the reinstall prompt.
Try This:
npm uninstall -g <package_name>
E.g: npm uninstall -g webpack

"libsass bindings not found. Try reinstalling node-sass"

So today I was trying to install MeepBot for StreamMe, and I ran into the error that says: "'libsass' bindings not found. Try reinstalling 'node-sass'." I reinstalled it like a million times. I have tried: "npm un/install --save-dev node-sass," "npm rebuild node-sass," etc. Can someone please give me an answer to my problem?
Picture: http://prntscr.com/axbxu8
P.S. keep in mind, I am using CentOS 6.
According to node-sass project's README.md only binaries for "popular platforms"(i.e. Windows/Mac) are included and you may need to build for other platforms like CentOS.
Here are roughly the steps (reading the readme would give you a better idea):
- cd to the node-sass directory within your project source.
- node scripts/install.js
- node scripts/build.js
Should see a message like Binary is fine; exiting.
Try to run npm rebuild node-sass again and it should work!
have you tried reinstalling everything? rm -rf node_modules; npm i. i've had to do that multiple times before.
otherwise, npm rebuild node-sass should work unless there are multiple versions of node-sass in your dependency tree - then maybe not. are you using npm v3+?
I would suggest try upgrading your gcc compiler as node-sass uses gcc to compile. And then try this -
npm rebuild node-sass
If that doesn't work then try runing this code (you must be using node version 4 or above).
npm install -g n
rm -R node_modules/
npm uninstall --save-dev node-sass
npm install --save-dev node-sass#2
npm install
npm -g install node-gyp#3
npm rebuild node-sass
If you are using multiple version of node then you will have to run npm rebuild node-sass every time you change node version.
You can also use gulp-sass npm install gulp-sass#2 if you want.
I was facing this issue. In my case the parent package.json was referring to new version of node-sass but the version of gulp-sass was referring to old node-sass. As soon as I updated gulp-sass to latest version, and ran 'npm rebuild node-sass', issue was gone.

Error "Cannot find module 'npmlog'" after "npm update -g"

I have NVM 0.30.1 and used it to install node.js v5.4.0 (with NPM 3.5.4) on Fedora 22. When I run npm update -g, I receive the following warnings:
npm WARN EBUNDLEOVERRIDE Replacing bundled npm > init-package-json with new installed version
npm WARN EBUNDLEOVERRIDE Replacing bundled npm > node-gyp with new installed version
npm WARN EBUNDLEOVERRIDE Replacing bundled npm > npm-install-checks with new installed version
npm WARN EBUNDLEOVERRIDE Replacing bundled npm > npmlog with new installed version
npm WARN EBUNDLEOVERRIDE Replacing bundled npm > read-package-json with new installed version
And after that, when I run npm I get this error:
module.js:328
throw err;
^
Error: Cannot find module 'npmlog'
at Function.Module._resolveFilename (module.js:326:15)
at Function.Module._load (module.js:277:25)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at /home/peflorencio/.nvm/versions/node/v5.4.0/lib/node_modules/npm/bin/npm-cli.js:20:13
at Object.<anonymous> (/home/peflorencio/.nvm/versions/node/v5.4.0/lib/node_modules/npm/bin/npm-cli.js:76:3)
at Module._compile (module.js:398:26)
at Object.Module._extensions..js (module.js:405:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
Does anyone know what it is and how to solve it?
Thanks
What fixed this for me was
sudo rm -rf /usr/local/lib/node_modules/
and then re-installing node (with npm).
Thanks for the answers. It was a bug and it has already been fixed in Node v5.4.1. Now it's working as usual.
It looks like npm update -g cannot update npm to the newest version. I solve the problem by updating npm installation manually.
Install/ reinstall node to get the bundled npm
run npm install -g npm#3.5.4 to update the global npm installation
now npm update -g should work
I have faced the same issue in my Windows 10 PC. After looking into solutions, since i couldn't find the exact solution for the issue i was facing
Cannot find module 'npmlog'
I just uninstalled the node js and then, deleted both 'npm' and 'npm-cache' in
"C:\Users\YourPCName\AppData\Roaming"
Then, i downloaded the latest version of node from Node JS Website
And, installed node js
After that i checked with the path in environment variables.
Finally run the command prompt 'run as administrator' and npm install npm -g
Checking your version will show the latest version. 'npm -v'
I got the latest version - v3.10.9
Try this. this should work.
If people with linux are facing the problem, here is the solution:
As of the date of this post, the NPM version packaged with Nodejs doesn't work. If you installed this package, run
sudo rm -rf /usr/local/bin/npm
sudo apt-get install node
sudo mv /usr/bin/npm /usr/local/bin/npm
New version should be 3.10.8 and the old error gone
init-package-json, node-gyp, npm-install-checks, npmlog, read-package-json didn't installed correctly. Not sure why though.
Didn't find the root cause for the issue but I used the hacky way to install the packages above for now:
Roll back to the previous node version which npm didn't be updated. For example, nvm use iojs
cd to where npm installed, for example, cd /home/peflorencio/.nvm/versions/node/v5.4.0/lib/node_modules/npm and reinstall those packages like rm -rf node_modules/init-package-json && npm install init-package-json etc.
Some of the answers already answered the question, but I will still like to throw in my own idea. I encountered same issue after I was told to run npm update -g npm after running that piece of code, the error started. I solved mine by using Node Version Manager(nvm):
nvm install 8
Note: not actually 8, but to a version of your choice e.g(6,5). Writing the version number will automatically install the stable of the version specified.
After the installation you should get a CLI message:
Now using node v8.11.4 (npm v5.6.0)
If you're using a Mac, perform the following steps, to remedy (assuming you have Homebrew installed already):
sudo rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/npm*
(to overcome bash: /usr/local/bin/npm: No such file or directory error):
hash -r
Then go ahead with updating brew (to keep its kegs up to date) and the reinstallation process, linking is optional.
brew update
brew reinstall node
brew link --overwrite node
At any point inbetween you can use npm -v or node -v to test whether or not you are making progress. If you have node returning a version, but not npm then you will need to add your path to your environment with:
export PATH="/usr/local/bin:$PATH"
There is an option to bump npm without reinstalling node.
#### # this will remove current npm
rm -rf /usr/local/lib/node_modules/npm/
#### # install npm from sources. Version 3.5.x will be installed
apt-get update
apt-get install npm
#### # install the newest npm version. Bumping from 3.5.X to 6.14.X goes without any issue :)
/usr/bin/npm install npm#latest -g
#### # additionally, npm with version 3.5.x is not added to $PATH, so it's not used.

Resources