error /node_modules/node-sass: Command failed
Asked Answered
V

33

297

When I tried install vue store front in my local but when I tried "yarn install" command I get following error. How can I solve this error? How can I solve this error?

error /var/www/html/vue-storefront/node_modules/node-sass: Command failed.
Exit code: 1
Command: node scripts/build.js
Arguments: 
Directory: /var/www/html/vue-storefront/node_modules/node-sass
Output:
Building: /usr/bin/node /var/www/html/vue-storefront/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
gyp info it worked if it ends with ok
gyp verb cli [
gyp verb cli   '/usr/bin/node',
gyp verb cli   '/var/www/html/vue-storefront/node_modules/node-gyp/bin/node-gyp.js',
gyp verb cli   'rebuild',
gyp verb cli   '--verbose',
gyp verb cli   '--libsass_ext=',
gyp verb cli   '--libsass_cflags=',
gyp verb cli   '--libsass_ldflags=',
gyp verb cli   '--libsass_library='
gyp verb cli ]
gyp info using [email protected]
gyp info using [email protected] | linux | x64
gyp verb command rebuild []
gyp verb command clean []
gyp verb clean removing "build" directory
gyp verb command configure []
gyp verb check python checking for Python executable "/usr/bin/python3.6" in the PATH
gyp verb `which` succeeded /usr/bin/python3.6 /usr/bin/python3.6
gyp ERR! configure error 
gyp ERR! stack Error: Command failed: /usr/bin/python3.6 -c import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack   File "<string>", line 1
gyp ERR! stack     import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack                                ^
gyp ERR! stack SyntaxError: invalid syntax
gyp ERR! stack 
gyp ERR! stack     at ChildProcess.exithandler (child_process.js:303:12)
gyp ERR! stack     at ChildProcess.emit (events.js:321:20)
gyp ERR! stack     at maybeClose (internal/child_process.js:1026:16)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
gyp ERR! System Linux 4.15.0-88-generic
gyp ERR! command "/usr/bin/node" "/var/www/html/vue-storefront/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd /var/www/html/vue-storefront/node_modules/node-sass
gyp ERR! node -v v13.9.0
Varied answered 25/2, 2020 at 12:7 Comment(4)
It's failing because python3 is used here. Create a .npmrc file in the project folder containing python = "/usr/bin/python2.7" and install. According to link, python 3.x.x is not yet supported.Bidle
Hi @NaceurBouhamed, I tried it but it's not working and giving same errorVaried
I got the same issue on node alpine image, if it helps github.com/nodejs/docker-node/issues/282Ansilma
node is the crappiest technology ever for developing :D Starting project is always a nightmare of manually fixing dependencies.Corneliuscornell
H
383

I had the same problem and I solved with the steps:

  1. If your are on Apple M1 Chip, run Terminal with Rosetta 2 (optional, only necessary if you have the Node installed with Rosetta)
  2. Check your node-sass version in your package.json and compare with the following table:
NodeJS Supported node-sass version Node Module
Node 20 9.0+ 115
Node 19 8.0+ 111
Node 18 8.0+ 108
Node 17 7.0+, <8.0 102
Node 16 6.0+ 93
Node 15 5.0+ 88
Node 14 4.14+ 83
Node 13 4.13+, <5.0 79
Node 12 4.12+ 72
Node 11 4.10+, <5.0 67
Node 10 4.9+, <6.0 64
Node 8 4.5.3+, <5.0 57
Node <8 <5.0 <57
  1. Check your Node version with: node --version
  2. Install the Nodejs version according with your node-sass, if your are using NVM, run: nvm use DESIRED_VERSION
  3. Clean old node_modules deleting the folder or type this on terminal: rm -rf node_modules
  4. Run: npm install

Resource:

Henleyonthames answered 31/5, 2021 at 17:31 Comment(11)
I am running Angular and updating my node-sass in package.json to 6.0.1 to match my node 16... that did the trick.Paw
Thanks! that was a good hint. I had to downgrade my node version and it worked.Gersham
Thanks Angelo! i downgraded my node from 17 to 13 and now it runs. I'm waiting until the day Rails 7 is out and we get rid of that webpacker! seems that node-sass is not the only one old package on itWatercolor
Using bootstrap-npm-starter. Upgraded node-sass in package.json to ^6.0.0 did the trick! Thank you.Aa
Depends a lot on which context you need it. My Vue.js solution didn't run npm i with node 16 and I had to downgrade it to node 14. Thanks for the post!Epiphora
thanks a lot. you should check node version ( node -v ) then install equivalent node-sass version according above table. In my case I constrained to downgrade node from 16 to 14Categorize
If you are on Rails 6 you might be using Webpacker (@rails/webpacker) 5.4.3 or below. This gem includes node-sass as a dependency stuck to version ^4.14.1, so you won't see it directly in package.json but you will find it as a dependency of @rails/webpacker in package.json-lock. As according to this correct answer, you would then need to use the lower version of Node (14) to be compatible.Condillac
In this answer, the "+" symbols are incorrect-- they imply that later versions of Node are backward compatible, but they are not, leading precisely to the original issue: If you are on node-sass v 5.0, you need to downgrade to Node 15. If you are on node-sass v 4, you need to downgrade to Node 14, etcCondillac
I'm not the author of this table, I got it from Node SASS NPM docs npmjs.com/package/node-sass . And the "+", for me, it's the latest small version, for example, 6.0+ can be 6.1, 6.2, ... so on, but not 7.0.Semiconscious
THis looks like a recurring problem forever. node_sass should at least provide a message if this happens which node version it is compatible with.Motley
Thank you!! Finally, after a day of search..Truculent
C
184

I had the same issue upgraded the node-sass version to be the same as node version. with yarn just run:

yarn add node-sass

this will upgrade the version and fix the issue

Coarsen answered 21/6, 2020 at 6:53 Comment(5)
Not working. Got "Node.js Sass version 7.0.0 is incompatible with ^4.0.0". Need to do: yarn remove node-sass, yarn add sass.Censorious
Just yarn add node-sass worked good for me. ThanksLorileelorilyn
This solution worked for me. I was building VueJS application on NodeJS ver. 16.x on Ubuntu.Sandblast
Tried both node-sass, sass doesn't workAnnapolis
@ChristiaanWesterbeek 's solution was the only one that worked for me on an m1 macSaundra
G
88

I am running Rails 6 and for some reason it was pulling webpacker 4.3.0 which was pulling node-sass 4.3.0 rather than 6.0.0 which is the latest as of the date of this post.

What worked for me is the following:

  1. Deleting the node_module folder, package-lock.json and yarn.lock
  2. In my package.json, I upgraded rails/webpacker: 5.3.0.
  3. I then re-ran yarn install.
  4. Then I ran yarn add node-sass

That worked like a charm, after trying everything else above.

I believe those were the exact steps, although to be honest I have been trying sooo many things and they didn't work and I finally got it to work so there is a possibility I may have missed a step, but I did my best to re-create it for any future frustrated soul out there.

Genisia answered 12/5, 2021 at 8:29 Comment(6)
Step 4. wasn't required in my situationRude
Didid't worked for me. It shows: gyp ERR! cwd /Users/reinier/src/00_private/ror/reiniergarcia/node_modules/node-sass gyp ERR! node -v v16.3.0 gyp ERR! node-gyp -v v3.8.0Ensue
Thank for this, it was the last step getting my project working on an M1 Mac!Unipod
All I did was step #2 and then ran a yarn and that worked for me.Kazantzakis
Simply doing steps #2 and #3 worked for me. Thanks!Kreiker
step 2 solve my problem! ThanksEtom
G
49

Try installing sass instead of node-sass. It worked well for me.

yarn remove node-sass
yarn add sass
Gemperle answered 10/4, 2021 at 19:53 Comment(1)
This should be #1 pick. node 18 is stable so downgrading to anything below is security risk as of 2023. Here is deeper explanation of above solution: [write.w5hnews.com/u/…Ceres
E
28

If it's a Rails project, upgrading webpacker did the job for me.

yarn add @rails/webpacker
Elijaheliminate answered 25/12, 2021 at 10:10 Comment(3)
Thanks that worked for me for a Rails 6.x project.Guadalcanal
This is the fix the worked for me. didn't know there was a @rails/webpacker package.Mazda
after upgrading to OSX 12.5, my Rails 5.2 project fail to start, terminal shows errors of node-sass but... tried this solution fix everything, why?Alane
F
19

Just upgrade your sass version in your yarn.lock file. For node 14 the appropriate version for node-sass is 4.14.
So adapt to your node version.

Fulminate answered 6/5, 2020 at 10:14 Comment(1)
This didn't quite get there for node 16 - my package.json specified webpacker v4.3.0 and it includes node-sass as a dependency. Updating webpacker to 5.3.0 was the solution for me.Melpomene
S
15

I changed the node version from 16.0 to 14.x in my package.json file and it worked.

Sternway answered 8/6, 2021 at 6:3 Comment(1)
It worked for me too. I wondering why 16 is not working though.Rooftree
V
10

Solutions here don't work for me. Until I delete the node_modules folder and yarn.lock.

rm -rf node_modules
rm yarn.lock
yarn instal
Voltaire answered 11/2, 2021 at 0:45 Comment(1)
In my case it was a sub dependancy and not even listed into package.json. The issue was into yarn.lock / package-lock.json. It seems to be a common issue when reviving projects from the github graveyardApollonian
L
8

Faced the same issue. If you look at the error stack, it says:

Error: Command failed: /usr/bin/python3.6 -c import sys; print "%s.%s.%s" % sys.version_info[:3];
   File "<string>", line 1
     import sys; print "%s.%s.%s" % sys.version_info[:3];
                                ^
 SyntaxError: invalid syntax

It's trying to use Python2 but instead uses Python3 which is not supported.

My system runs Python3 when called using the python command, so I fixed this by installing Python2 and aliasing it to the python command:

alias python=pyhton2.7
Lonne answered 26/5, 2020 at 8:55 Comment(4)
Hi, where did you add the above command? I'm getting the same error @RottenCandyTaxonomy
@Taxonomy run it in the shell before run the install command, or put it in the .bashrc or somewhere similar (if you're on Linux).Lonne
You can just use npm config set python python2Wiggle
In my case it was looking for "python2" which I did not have. Installed python2 and it worked directly.Km
S
8

Having same issue here. I did

nvm install 14  

because the node-sass version I have in package.json is 4.14.1 then this will display - Now using node v14.19.3 (npm v6.14.17) after I did

yarn install

and it was a success

Supermarket answered 21/6, 2022 at 13:11 Comment(1)
hi, this is was the answer for meConsonant
H
6

i have been facing the same problem for a while now on rails app, and was solved by upgrading webpacker:

# check your Gemfile for version restrictions
bundle update webpacker

# overwrite your changes to the default install files and revert any unwanted changes from the install
rails webpacker:install

# yarn 1 instructions
yarn upgrade @rails/webpacker --latest
yarn upgrade webpack-dev-server --latest

see: https://github.com/rails/webpacker#upgrading

props to chase439 : https://github.com/sass/node-sass/issues/2447

Hilmahilt answered 8/9, 2021 at 11:7 Comment(0)
L
6

As for me, the issue was resolved after upgrading to the latest v7.0.1. Based on this github issue, node-sass team has fixed it in version 7.0 and above.

I'm using node v16.13.2 and on Apple M1 Chip.

Laryngo answered 26/8, 2022 at 3:58 Comment(0)
C
5

my solution use node v10.19.0

https://github.com/nodejs/docker-node/issues/1149#issuecomment-552705885

Had a similar problem with /node_modules/node-sass: Command failed on building my application, which also occurred within the last week without any updates on my end.

Had a look at the node-sass docs and the node version on the server and it was using node v12.13.0 and the version of node-sass was 4.9.x.

in the node-sass release docs it lists that for node v12 you need to have node-sass v4.12 and up.

Updating node-sass version corrected the build for me, hope it helps for you too.

node Release docs: https://github.com/sass/node-sass/releases

Crowns answered 3/11, 2020 at 19:47 Comment(1)
I encountered this issue trying to replicate a site on EC2 - this made me think to double check I had installed the same version of Node that was used to develop the site. I had not.Edvard
M
4

Install node-sass globally with yarn

Or Add node-sass to your project

Mosier answered 25/2, 2020 at 12:14 Comment(3)
Hi @Eren I have tried it but it gives me same errorVaried
@Varied I downloaded the sample in this repo StoreFront and simply called npm install did not throw an error. Actually I'm not a yarn expert but you can also try clean yarn's cached and globally downloaded files and re- install yarn. By the way I'm using macOs Catalina.Mosier
Thanks for your info. Actually I used nodejs with magento2 in other way and it is working fineVaried
C
4

If you are getting this error while trying to deploy your project on Heroku, these steps worked for me:

On 16 December 2021, Heroku changed the Node version to 16.13.1 (which was previously 12.16.2). Since we have dependencies such as node-sass v4.14.1 which requires Node v14, we need to specify the Node version Heroku should use.

  • First, we need to use multiple buildpacks, which will specify to install Node first then install Ruby (Read more from Heroku).

Please make you install them in the order below

$ heroku buildpacks:add heroku/nodejs
$ heroku buildpacks:add heroku/ruby
  • Verify that the buildpacks are installed
$ heroku buildpacks

  1. heroku/nodejs
  2. heroku/ruby
  • If buildpacks are not in the order above, remove each of them and add them again. If, for example, ruby comes first, you can just remove it, then add it again as below.
$ heroku buildpacks:remove heroku/ruby

Add it again

$ heroku buildpacks:add heroku/ruby

Now you should have the correct ordering.

{
  ...
  "engines": {
    "node": "14.x"
  },
  ...
}
  • Make sure to run $ yarn install to update your dependencies based on the new Node version.

This happens because your application contains a Yarn lockfile yarn.lock which does not match the dependencies in package.json. This can happen if you use npm to install or update a dependency instead of Yarn.

  • If applicable commit to Git and Deploy!

I found this solution in this article and it worked for me, hope I could help someone

Cobos answered 18/4, 2022 at 20:56 Comment(0)
M
3

I solved this issue by installing the python 2.7 version on windows os.I had Python 3 installed before. This error happens because of the python version 3.

Messenia answered 4/10, 2020 at 16:49 Comment(0)
A
3

On top of the suggested resolutions, I've found that sometimes yarn.lock has a node-gyp locked version for node-sass. When I changed it from 3.8.0 to 8.4.1 everything worked.

Angeli answered 15/12, 2021 at 11:43 Comment(0)
E
2

Another option is to update your PATH environment variable to point to Python2 instead of Python3 (remove the Python3 directory from PATH)

Escapement answered 26/6, 2021 at 13:13 Comment(0)
P
2

For macOS users

If you need to use node-gyp from within npm (e.g. through npm install), you will have to install node-gyp (either globally with -g or to a predictable location) and tell npm where the new version is.

In my case, turns out my project defaulted to using node-gyp v3.8.0 to building my project's modules.

To remedy that, I ran the following commands:

npm config set node_gyp /usr/local/lib/node_modules/node-gyp
npm install

I hope this is insightful for anyone going through the same.

Paulsen answered 31/1, 2022 at 1:30 Comment(0)
P
2

I was using "node-sass": "^4.13.1" in my package.json. I updated to "node-sass": "6.0.0" and it worked. My Node.js version is v16.14.0.

Polygnotus answered 23/12, 2022 at 12:0 Comment(0)
D
1

I ran into this issue when containerising a VueJs app. I was using the node:15.12.0-alpine tag as base image before but the issue was fixed once I changed to the full node image (node:15.12.0) that uses debian-stretch.

Durmast answered 30/3, 2021 at 6:21 Comment(0)
T
1

It's failing because python3 is used here. Create a .npmrc file in the project folder containing python = "/usr/bin/python2.7" and install. According to link, python 3.x.x is not yet supported. – NaceurBouhamed Feb 25 '20 at 12:28

****python = "localpath/python27/python.exe"

RESOLVED

Tribe answered 26/5, 2021 at 18:54 Comment(0)
A
1

TBH my problem was that I tried to "npm install angular-cli" instead of "npm install @angular/cli", hope this helps other dummies like me :)

Assured answered 3/11, 2021 at 8:58 Comment(0)
A
1

For Vue Storefront 1, you can try using node version 10.16.0 and it will work fine.

Alvarez answered 16/1, 2022 at 4:25 Comment(0)
P
1

For Rails Users

For me this was an easy fix. If you are using nvm, just make sure you have the correct node version installed and in use.

Steps:

  1. Check your node version node -v
  2. If the node version is different to the one your rails project is using then update (example using node 16 but project is using node 14), run nvm use 14
  3. run yarn install

This should work.

Peppi answered 3/11, 2022 at 1:7 Comment(0)
H
1

detect your current npm config python path by run:
$ npm config get python

if it another from your current python path, so change it by run:
$ npm config set python=<YOUR_PYTHON_DIR_PATH>

(for example in my machine it's: C:\python311)

Heddi answered 9/11, 2022 at 8:16 Comment(0)
L
0

With gulp I got "Node Sass could not find a binding for your current environment: Linux 64-bit with Node.js 12.x

Found bindings for the following environments:

  • Linux 64-bit with Unsupported runtime (93)

This usually happens because your environment has changed since running npm install. Run npm rebuild node-sass to download the binding for your current environment."

So I ran npm rebuild node-sass and that worked! Then npm install and everything went ok.

Lynx answered 13/7, 2021 at 19:20 Comment(0)
A
0

Got very strange solutions around after reading the heroku logs.

Initially I have added buildpacks into this order: heroku/ruby heroku/nodejs

enter image description here

But after looking into the complete log and error i have change the order: heroku/nodejs heroku/ruby

enter image description here

After that precompile works nicely.

Alewife answered 28/1, 2022 at 14:30 Comment(0)
O
0

This happened to me a day after upgrading node. I had to revert to a lower node version. I had upgraded to 16.13.2 from 14.15.4

Orff answered 4/2, 2022 at 12:9 Comment(0)
F
0

I had this problem when I was using a newer version of Node (16 via nvm) than my current version of node-sass (4.9) supported. Falling back to Node 10 worked to relieve the issue. Ângelo Polotto's answer has a good compatibility chart to follow.

Feoff answered 7/7, 2022 at 2:27 Comment(0)
S
0

From personal perspective you had better to use:

 yarn add axios
Sphagnum answered 30/9, 2022 at 15:2 Comment(0)
M
0

if your project has .nvmrc file, then install/use nodejs listed on that file.

inside my .nvmrc file, it's listed v8, so I'm just installing node v8.

.nvmrc is specifying or locking your application with a specific node.js version.

Mellott answered 8/5, 2023 at 2:57 Comment(0)
F
0

2024 solution

  1. add .npmrc file.
  2. add python = "/usr/bin/python3" in the .npmrc
  3. yarn install

Thanks @NaceurBouhamed for the comment.

node is the crappiest technology ever for developing :D Starting project is always a nightmare of manually fixing dependencies. – Vasil Valchev

Fenelia answered 21/4 at 12:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.