Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot assign to read only property 'cflags' of object '#<Object>' #2752

Closed
guanzhengyinqin opened this issue Oct 27, 2022 · 12 comments
Closed
Labels
ffi-napi Node Sass --> Dart Sass https://github.com/sass/node-sass/issues/2952

Comments

@guanzhengyinqin
Copy link

guanzhengyinqin commented Oct 27, 2022

build node-sass error

c++ compiler
gcc -E -dM - </dev/null | grep "STDC_VERSION"
#define STDC_VERSION 201710L

details
npm --verbose
gyp info it worked if it ends with ok
gyp verb cli [
gyp verb cli '/usr/bin/node',
gyp verb cli '/home/guanzheng/document/workspace/codeworkspace/webstormProject/Saber/node_modules/node-sass/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 find Python Python is not set from command line or npm configuration
gyp verb find Python Python is not set from environment variable PYTHON
gyp verb find Python checking if "python3" can be used
gyp verb find Python - executing "python3" to get executable path
gyp verb find Python - executable path is "/usr/bin/python3"
gyp verb find Python - executing "/usr/bin/python3" to get version
gyp verb find Python - version is "3.10.8"
gyp info find Python using Python version 3.10.8 found at "/usr/bin/python3"
gyp verb get node dir no --target version specified, falling back to host node version: 19.0.0
gyp verb command install [ '19.0.0' ]
gyp verb install input version string "19.0.0"
gyp verb install installing version: 19.0.0
gyp verb install --ensure was passed, so won't reinstall if already installed
gyp verb install version is already installed, need to check "installVersion"
gyp verb got "installVersion" 9
gyp verb needs "installVersion" 9
gyp verb install version is good
gyp verb get node dir target node version installed: 19.0.0
gyp verb build dir attempting to create "build" dir: /home/guanzheng/document/workspace/codeworkspace/webstormProject/Saber/node_modules/node-sass/build
gyp verb build dir "build" dir needed to be created? /home/guanzheng/document/workspace/codeworkspace/webstormProject/Saber/node_modules/node-sass/build
gyp verb build/config.gypi creating config file
gyp ERR! UNCAUGHT EXCEPTION
gyp ERR! stack TypeError: Cannot assign to read only property 'cflags' of object '#'
gyp ERR! stack at createConfigFile (/home/guanzheng/document/workspace/codeworkspace/webstormProject/Saber/node_modules/node-sass/node_modules/node-gyp/lib/configure.js:117:21)
gyp ERR! stack at /home/guanzheng/document/workspace/codeworkspace/webstormProject/Saber/node_modules/node-sass/node_modules/node-gyp/lib/configure.js:84:9
gyp ERR! stack at FSReqCallback.oncomplete (node:fs:189:23)
gyp ERR! System Linux 6.0.2-arch1-1
gyp ERR! command "/usr/bin/node" "/home/guanzheng/document/workspace/codeworkspace/webstormProject/Saber/node_modules/node-sass/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd /home/guanzheng/document/workspace/codeworkspace/webstormProject/Saber/node_modules/node-sass
gyp ERR! node -v v19.0.0
gyp ERR! node-gyp -v v7.1.2
gyp ERR! Node-gyp failed to build your package.

@cclauss
Copy link
Contributor

cclauss commented Oct 27, 2022

Here is the text that you deleted when you opened this issue...

Please look thru your error log for the string gyp info using node-gyp@ and if the version number is less than the current release of node-gyp then please upgrade using the instructions at https://github.com/nodejs/node-gyp/blob/master/docs/Updating-npm-bundled-node-gyp.md and try your command again.

Requests for help with node-sass are very common. Please be aware that this package is deprecated, you should seek alternatives and avoid opening new issues about it here.

@cclauss cclauss closed this as completed Oct 27, 2022
@Jakobeha
Copy link

Note the above instructions don't work in npm 9. What did work and force nodejs to use the correct node-gyp version was adding it to devDependencies as described here

@alper
Copy link

alper commented Sep 14, 2023

This is a relatively old project. I'm not sure how randomly upgrading node-gyp will solve it and not break a bunch of other things.

gyp info using [email protected]
gyp info using [email protected] | darwin | arm64

@cclauss cclauss added the Node Sass --> Dart Sass https://github.com/sass/node-sass/issues/2952 label Sep 14, 2023
@cclauss
Copy link
Contributor

cclauss commented Sep 14, 2023

@alper
Copy link

alper commented Sep 14, 2023

I can't upgrade it because it's not one of our main dependencies. Some other package is depending on it.

@xzifan
Copy link

xzifan commented Dec 13, 2023

I was trying to rebuild ref-napi and ffi-napi for electron and the same error showed up.

Adding "node-gyp": "^10.0.1" to devDependencies fixed it in my case.

@cclauss
Copy link
Contributor

cclauss commented Dec 19, 2023

@kapilshanaz
Copy link

kapilshanaz commented Jan 6, 2024

Adding dev dependencies
"node-gyp": "10.0.1", "nan": "2.18.0"
Also adding
"resolutions": { "nan": "2.18.0" }
to package.json worked for me for Node.JS 20 build failure

@Guilherhast
Copy link

In my case moving the folder $HOME/.config/yarn/global to $HOME/.config/yarn/global_bak solved the issue.
It was a conflict between the packages installed to user and the ones installed in the operating system.

@remixer-dec
Copy link

remixer-dec commented Nov 26, 2024

I was trying to install a project from 2022 that has node-sass in its dependencies.
None of the suggested solutions worked for me, here is what worked:

@cclauss
Copy link
Contributor

cclauss commented Nov 26, 2024

Correct. Repeating from above (#2752 (comment)), node-sass was deprecated long ago.

@LukeShu
Copy link

LukeShu commented Jan 27, 2025

Sure, but this is a node-gyp problem, not a node-sass problem.

Since this ticket is what comes up if you search for Cannot assign to read only property 'cflags' of object '#<Object>', whether or not you're using node-sass: The problem is that you'll need node-gyp 8.2.0 or later for Node 16+. In Yarn syntax, you can force this with:

  "resolutions": {
    "//": [
      "Pull in https://github.com/nodejs/node-gyp/pull/2368 (first included in",
      "v8.2.0) for compatibility with Node 16+"
    ],
    "node-gyp": "8.2.0",
  }

You should of course upgrade to a newer node-gyp if you can; but if you're trying to get an old project going again, you probably want to be as conservative as you can for a bit.

If you are using node-sass, you'll need the above, but you'll also need at least node-sass 6.0 for that version of node-gyp:

  "resolutions": {
    "//": [
      "Pull in https://github.com/nodejs/node-gyp/pull/2368 (first included in",
      "v8.2.0) for compatibility with Node 16+"
    ],
    "node-gyp": "8.2.0",
    "//": [
      "Since node-gyp 8.2.0 requires C++20 or later, we require at least",
      "node-sass v6 which is the first to no longer force `-std=c++0x`"
    ],
    "node-sass": "6.0.0"
  }

You should of course look into migrating from node-sass to sass, but if node-sass is being pulled in by another large dependency (maybe Vue 2), then upgrading major versions of other things is likely to be a larger task you don't want to tackle right away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ffi-napi Node Sass --> Dart Sass https://github.com/sass/node-sass/issues/2952
Projects
None yet
Development

No branches or pull requests

9 participants