Node Sass with apple m1, Big Sur and arm64
Asked Answered
A

14

92
 Error: Node Sass does not yet support your current environment: OS X Unsupported architecture (arm64) with Unsupported runtime (93)
 For more information on which environments are supported please see:
 https://github.com/sass/node-sass/releases/tag/v4.14.1
at module.exports (/Users/hhag/Desktop/test_gulp/node_modules/node-sass/lib/binding.js:13:13)
at Object.<anonymous> (/Users/hhag/Desktop/test_gulp/node_modules/node-sass/lib/index.js:14:35)
at Module._compile (node:internal/modules/cjs/loader:1109:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1138:10)
at Module.load (node:internal/modules/cjs/loader:989:32)
at Function.Module._load (node:internal/modules/cjs/loader:829:14)
at Module.require (node:internal/modules/cjs/loader:1013:19)
at require (node:internal/modules/cjs/helpers:93:18)
at Object.<anonymous> (/Users/hhag/Desktop/test_gulp/node_modules/gulp-sass/index.js:166:21)
at Module._compile (node:internal/modules/cjs/loader:1109:14)

this error occures when I start to use gulp. is there a solution for using gulp-sass with apple m1? thanks

Almonry answered 23/6, 2021 at 7:44 Comment(0)
R
121

I also had issues installing node-sass on M1, and ended up using the opportunity to replace it with sass, as recommended on the LibSass deprecation notice.

https://sass-lang.com/blog/libsass-is-deprecated

If you’re a user of Node Sass, migrating to Dart Sass is straightforward: just replace node-sass in your package.json file with sass. Both packages expose the same JavaScript API.

As mentioned by @Ti Hausmann you can try with:

npm uninstall node-sass
npm install --save-dev sass

The replacement was completely smooth, it worked on M1, and I couldn't notice any performance impact locally or on the CI.

Rowe answered 12/7, 2021 at 19:22 Comment(2)
Thanks, this worked. I did npm uninstall node-sass, npm install --save-dev sass.Brundisium
see an answer below from m_kos. it seems more sensible to just change dependencies in node-sassFiddling
S
94

For npm > 6.9 you can switch your dependency to dart-sass/sass with just one line and from there just use sass as you would before.

npm install node-sass@npm:sass

Squadron answered 24/9, 2021 at 13:40 Comment(8)
I believe this is the correct answer, non of the others above helpedView
tnx bro, it worked for meStorer
Node v 16.13.0 and NPM v 8.1.4 here; worked like a charm 👍Selfliquidating
This command gave me dependency tree errors, but a simple npm i sass worked.Brundisium
yarn add sass worked for me.Krebs
This works for now, but I am not sure how it will behave once its in a Source Control system like git and peers who might be working on other machines, since lock file needs to be committed as well !Brobdingnagian
This worked on node v14.20.1, npm v6.14.16 without any further errors.Marcasite
Thanks @Squadron ! This worked perfectMaltose
C
37

I think, you are using an M1 Mac. And node-sass currently doesn't support it natively. See: https://github.com/sass/node-sass/issues/3033

For now you can set target arch for running it through Rosetta with:

rm -rf node_modules
npm install --target_arch=x64
Cyndi answered 24/6, 2021 at 8:0 Comment(5)
Hi, Murart Corlu It does work on local machine when i tries to build Image using Dockerfile it fails to install packages. Any help would be appreciatedOpine
Am facing same issue using dockerfile. Can you please share your solution if you were able to resolve itMancino
is there any workaround for docker @OpinePaprika
@KapilGupta are you able to resolve this issue somehow?Paprika
This solutions works, you need to run all commands on i386, using arch -x86_64 zsh, then remove all node_modules, uninstall node, install node and npm modules again (make sure that arch prints i386)Flotage
L
19

I ran into the same error when developing a Vue.js project with node-sass. I worked around this issue by downgrading to Node version 14.

I’ve done this with n, a Node’s version manager application. See this answer: https://stackoverflow.com/a/50287454.

Check which node version you’re using

$ node -v 
v16.3.0

Install n

$ npm install -g n

Get list of available Node versions you can install

$ n ls-remote --all
16.3.0
16.2.0
..
15.14.0
15.13.0
..
14.17.0
14.16.1
..

Install Node version 14

$ sudo n install 14

Lifeline answered 16/9, 2021 at 12:21 Comment(2)
+1, Bear in mind if one had a previous installation of node using brew, one will have to uninstall the brew's node with brew uninstall node so the n node version takes effectMonostrophe
I don't want to downgrade node version, is there no other way to fix this?Tallbot
U
6
  1. Reinstall node to version 14 by downloading from here https://nodejs.org/dist/v14.0.0/
  2. in your project folder run npm rebuild node-sass
Unwashed answered 18/11, 2021 at 17:47 Comment(2)
This is the answer that saved me thousand hours. Just downgrade to node 14 and problem is solved.Huskey
This was the only thing that worked for me after trying for ages!Vitriform
A
6

Just adding for completeness of the answer, that I came across this issue when using the serverless framework (https://www.serverless.com/).

I was receiving a node gyp build error using both Node 16 and 17.

Using nvm I installed node version 14 and this solved my issue.

The steps to fix were:

  1. nvm install v14
  2. nvm use 14

Then I was able to do a yarn command which installed and built correctly.

Ambsace answered 6/1, 2022 at 23:6 Comment(1)
After downgrading from node 17 to node 14 solved my issue.Sliver
F
5
  1. yarn add sass or npm install sass
  2. replace "node-sass": with "sass": in package.json
  3. rm -rf node_modules && npm install

Worked for me on my M1 MBP.

Fils answered 29/3, 2022 at 10:5 Comment(0)
T
4

Here is the official recomendation per gulp-sass Issue #803 - Apple M1 Chip Support

Switch to the sass compiler: Instructions

TL;DR:

  1. Install version 5 of node-sass that does not include a default Sass compiler:

npm install sass gulp-sass --save-dev

or, Yarn

yarn add sass gulp-sass --save-dev

  1. Explicitly set your compiler in your gulpfile:

const sass = require('gulp-sass')(require('sass'));

or, for ES6 modules

import gulpSass from 'gulp-sass';
const sass = gulpSass(dartSass);
Traynor answered 22/12, 2021 at 17:34 Comment(0)
C
3

Switching to Sass works just great in m1. As pointed in the top answers. And we should always be using sass in place of node-sass now as it's deprecated.

Here I want to point to one case that some may fall in. That if it's the case I think that would save you some time.

Case

You go and remove node-sass through npm uninstall or even by doing npm install node-sass@npm:sass as pointed in the second answer. You removed node-modules and package-lock.json.
And still having the same problem and somehow node-sass is getting compiled.

Not working even after trying to install sass?

If so the case. Make sure to check your dependencies versions. A good chance some of them depends on node-sass on there old versions.

Ex:

    "sass-loader": "^8.0.2",
    "styles-loader": "^1.0.2"

update the version to latest =>

    "sass-loader": "^12.4.0",
    "styles-loader": "^3.0.0"

That should do it. And make sure to check all the dependencies that can depend on node-sass and update them.

If for some reason that still is a problem. You can try adding

  "optionalDependencies": {
    "node-sass": "*"
  }

to package.json. I don't think it's necessary though.

Cockcrow answered 20/1, 2022 at 15:45 Comment(0)
F
1

This command worked for me,

npm uninstall node-sass -g && npm cache clean -force && npm install node-sass
Faradize answered 11/1, 2022 at 8:47 Comment(0)
P
1

I have struggle lot with issue my my brand new macOS Monterey M1 Chip Macbook Pro. None of solutions work except It's fix when I have set target arch for NPM installation using below command.

npm install --target_arch=x64
Pellagra answered 28/9, 2022 at 9:11 Comment(0)
A
1

The only command that worked for me was:

npm rebuild node-sass
Aposematic answered 16/10, 2023 at 18:47 Comment(0)
L
0

Yarn:

yarn remove node-sass
yarn add node-sass --dev
Lava answered 3/5, 2023 at 12:22 Comment(0)
B
0

Use this guide - https://github.com/dlmanning/gulp-sass#setting-a-sass-compiler. It helped me a lot. Just make sure in the end that gulp-sass version is greater than 5.

Bombast answered 7/6, 2023 at 14:3 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Jorgan

© 2022 - 2024 — McMap. All rights reserved.