macosnpmtypeerrornode-gypnpm-link

How do I fix npm ERR! gyp ERR! stack TypeError: Cannot assign to read only property 'cflags' of object '#<Object>' when running npm link some-dep


I am trying to run npm link felca-runtime and am getting the below error, which I can't find anything useful on online:

theo.hodges@DKH334L0G5 felca-nhsuk % npm link felca-runtime
npm notice Beginning October 4, 2021, all connections to the npm registry - including for package installation - must use TLS 1.2 or higher. You are currently using plaintext http to connect. Please visit the GitHub blog for more information: https://github.blog/2021-08-23-npm-registry-deprecating-tls-1-0-tls-1-1/
npm notice Beginning October 4, 2021, all connections to the npm registry - including for package installation - must use TLS 1.2 or higher. You are currently using plaintext http to connect. Please visit the GitHub blog for more information: https://github.blog/2021-08-23-npm-registry-deprecating-tls-1-0-tls-1-1/
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm ERR! code 1
npm ERR! path /Users/theo.hodges/accelerate/felca-nhsuk/node_modules/node-sass
npm ERR! command failed
npm ERR! command sh -c node scripts/build.js
npm ERR! Building: /Users/theo.hodges/.nvm/versions/node/v20.7.0/bin/node /Users/theo.hodges/accelerate/felca-nhsuk/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp verb cli [
npm ERR! gyp verb cli   '/Users/theo.hodges/.nvm/versions/node/v20.7.0/bin/node',
npm ERR! gyp verb cli   '/Users/theo.hodges/accelerate/felca-nhsuk/node_modules/node-gyp/bin/node-gyp.js',
npm ERR! gyp verb cli   'rebuild',
npm ERR! gyp verb cli   '--verbose',
npm ERR! gyp verb cli   '--libsass_ext=',
npm ERR! gyp verb cli   '--libsass_cflags=',
npm ERR! gyp verb cli   '--libsass_ldflags=',
npm ERR! gyp verb cli   '--libsass_library='
npm ERR! gyp verb cli ]
npm ERR! gyp info using node-gyp@7.1.2
npm ERR! gyp info using node@20.7.0 | darwin | arm64
npm ERR! gyp verb command rebuild []
npm ERR! gyp verb command clean []
npm ERR! gyp verb clean removing "build" directory
npm ERR! gyp verb command configure []
npm ERR! gyp verb find Python Python is not set from command line or npm configuration
npm ERR! gyp verb find Python Python is not set from environment variable PYTHON
npm ERR! gyp verb find Python checking if "python3" can be used
npm ERR! gyp verb find Python - executing "python3" to get executable path
npm ERR! gyp verb find Python - executable path is "/Library/Developer/CommandLineTools/usr/bin/python3"
npm ERR! gyp verb find Python - executing "/Library/Developer/CommandLineTools/usr/bin/python3" to get version
npm ERR! gyp verb find Python - version is "3.9.6"
npm ERR! gyp info find Python using Python version 3.9.6 found at "/Library/Developer/CommandLineTools/usr/bin/python3"
npm ERR! gyp verb get node dir no --target version specified, falling back to host node version: 20.7.0
npm ERR! gyp verb command install [ '20.7.0' ]
npm ERR! gyp verb install input version string "20.7.0"
npm ERR! gyp verb install installing version: 20.7.0
npm ERR! gyp verb install --ensure was passed, so won't reinstall if already installed
npm ERR! gyp verb install version is already installed, need to check "installVersion"
npm ERR! gyp verb got "installVersion" 9
npm ERR! gyp verb needs "installVersion" 9
npm ERR! gyp verb install version is good
npm ERR! gyp verb get node dir target node version installed: 20.7.0
npm ERR! gyp verb build dir attempting to create "build" dir: /Users/theo.hodges/accelerate/felca-nhsuk/node_modules/node-sass/build
npm ERR! gyp verb build dir "build" dir needed to be created? /Users/theo.hodges/accelerate/felca-nhsuk/node_modules/node-sass/build
npm ERR! gyp verb build/config.gypi creating config file
npm ERR! gyp ERR! UNCAUGHT EXCEPTION 
npm ERR! gyp ERR! stack TypeError: Cannot assign to read only property 'cflags' of object '#<Object>'
npm ERR! gyp ERR! stack     at createConfigFile (/Users/theo.hodges/accelerate/felca-nhsuk/node_modules/node-gyp/lib/configure.js:117:21)
npm ERR! gyp ERR! stack     at /Users/theo.hodges/accelerate/felca-nhsuk/node_modules/node-gyp/lib/configure.js:84:9
npm ERR! gyp ERR! stack     at FSReqCallback.oncomplete (node:fs:189:23)
npm ERR! gyp ERR! System Darwin 22.6.0
npm ERR! gyp ERR! command "/Users/theo.hodges/.nvm/versions/node/v20.7.0/bin/node" "/Users/theo.hodges/accelerate/felca-nhsuk/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
npm ERR! gyp ERR! cwd /Users/theo.hodges/accelerate/felca-nhsuk/node_modules/node-sass
npm ERR! gyp ERR! node -v v20.7.0
npm ERR! gyp ERR! node-gyp -v v7.1.2
npm ERR! gyp ERR! Node-gyp failed to build your package.
npm ERR! gyp ERR! Try to update npm and/or node-gyp and if it does not help file an issue with the package author.
npm ERR! Build failed with error code: 7

npm ERR! A complete log of this run can be found in: /Users/theo.hodges/.npm/_logs/2023-09-22T08_52_11_799Z-debug-0.log

I have tried updating npm, node-gyp, Python and clearing npm cache to no avail.

I'm running:

Node v20.7.0

npm 10.1.0

node-gyp v9.4.0

Python 3.9.6

macOS 13.5.2


Solution

  • In your case, it is possible that you have two different versions of node-sass installed, and node-gyp is trying to use the wrong version. To fix this, try uninstalling all versions of node-sass and then reinstalling the latest version: If you still enconter this problem, try to clear the node-gyp cache. Lastly, try redownloading node-gyp globally