Home > Back-end >  npm installing nonexistent node-sass
npm installing nonexistent node-sass

Time:04-29

We have a project that we're upgrading from node-sass to sass. We've removed the dependency on node-sass from package.json.

npm install works under node v15 (npm v7.7.6), but fails under node v16 (npm v8.7.0).

It's failing with

npm info run [email protected] postinstall

which is trying to compile libsass.

npm ERR! npm ERR! command sh -c node scripts/build.js npm ERR! npm ERR! Building: /Users/.../.nvm/versions/node/v16.14.2/bin/node /Users/.../.npm/_cacache/tmp/git-clonewTBZbR/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library= npm ERR! npm ERR! c '-DNODE_GYP_MODULE_NAME=libsass'...

I'm aware that node-sass and libsass are very dependent on node versions. What I can't figure out is where this dependency is coming from.

If I switch to node 15 and install (to create node_modules), I find:

npm ls node-sass shows (empty)

find . -type d -name 'node-sass' finds no such directory (same for libsass)

Recursively grepping node_modules for "node-sass" with ack --noignore-dir=node_modules node-sass shows only devDependencies and peerDependencies (such as the optional one for sass-loader). Installing with --legacy-peer-deps didn't help.

I've tried installing with --loglevel silly without seeing any more relevant information.

How can I determine what is attempting to install this dependency?

CodePudding user response:

I found the issue (it was a private corporate package that used an old version of node-sass and was being imported using git ssh).

Technique:

  1. In a new folder, run npm init -y
  2. Copy over dependencies/devDependencies from the project in question a chunk at a time (you could also npm i these individually, but you would have to @ the same version and it might take longer)
  3. After adding each chunk of dependencies, run npm i (or npm i --legacy-peer-deps if necessary)
  4. Optionally git init the folder (with a .gitignore for node_modules) and commit after each change to make it easier to revert
  5. Repeat from step 2 until you get the error

I made some educated guesses as to which packages could be the culprit, so I could test several dependencies at once.

In the end I narrowed it down to one package. Adding it caused the error.

Another option could be removing packages one by one (assuming your project is under source control) and attempting to install after each one.

  • Related