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

npm ERR! Cannot set properties of null (setting 'dev') #4064

Closed
2 tasks done
maksimr opened this issue Nov 18, 2021 · 25 comments
Closed
2 tasks done

npm ERR! Cannot set properties of null (setting 'dev') #4064

maksimr opened this issue Nov 18, 2021 · 25 comments
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release

Comments

@maksimr
Copy link

maksimr commented Nov 18, 2021

Is there an existing issue for this?

  • I have searched the existing issues

This issue exists in the latest npm version

  • I am using the latest npm

Current Behavior

npm install does not work if try to install one workspace to another

STR:

  • mkdir foo && cd ./foo
  • npm init -y
  • npm init -y -w ./pkg-a
  • npm init -y -w ./pkg-b
  • npm install ./pkg-a -w pkg-b

AR: npm ERR! Cannot set properties of null (setting 'dev')
ER: Behaviour similar to cd ./pkg-b && npm install ../pkg-a

Expected Behavior

No response

Steps To Reproduce

No response

Environment

  • npm: 8.1.0
  • Node: v16.13.0
  • OS: macOS 12.0.1
  • platform: Darwin arm64
60 verbose stack TypeError: Cannot set properties of null (setting 'dev')
60 verbose stack     at calcDepFlagsStep (/Users/maksim/.nvm/versions/node/v16.13.0/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/calc-dep-flags.js:34:21)
60 verbose stack     at visit (/Users/maksim/.nvm/versions/node/v16.13.0/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/calc-dep-flags.js:12:20)
60 verbose stack     at visitNode (/Users/maksim/.nvm/versions/node/v16.13.0/lib/node_modules/npm/node_modules/treeverse/lib/depth-descent.js:57:25)
60 verbose stack     at next (/Users/maksim/.nvm/versions/node/v16.13.0/lib/node_modules/npm/node_modules/treeverse/lib/depth-descent.js:44:19)
60 verbose stack     at depth (/Users/maksim/.nvm/versions/node/v16.13.0/lib/node_modules/npm/node_modules/treeverse/lib/depth-descent.js:82:10)
60 verbose stack     at depth (/Users/maksim/.nvm/versions/node/v16.13.0/lib/node_modules/npm/node_modules/treeverse/lib/depth.js:27:12)
60 verbose stack     at calcDepFlags (/Users/maksim/.nvm/versions/node/v16.13.0/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/calc-dep-flags.js:10:15)
60 verbose stack     at Arborist.[copyIdealToActual] (/Users/maksim/.nvm/versions/node/v16.13.0/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js:1400:7)
60 verbose stack     at Arborist.reify (/Users/maksim/.nvm/versions/node/v16.13.0/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js:153:35)
60 verbose stack     at async Install.install (/Users/maksim/.nvm/versions/node/v16.13.0/lib/node_modules/npm/lib/install.js:170:5)
61 verbose cwd /private/tmp/foo
@maksimr maksimr added Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release labels Nov 18, 2021
@thomazmz
Copy link

Same problem here. Using Node v17.3.0 and NPM v8.3.0

@nperez0111
Copy link

I was able to get around this by doing a npm ci

@gufeng0
Copy link

gufeng0 commented Jan 25, 2022

image
I have the same problem.

@chriskinsman
Copy link

chriskinsman commented Jan 27, 2022

Same issue but with slightly different repro.

Odd thing is in our monorepo some workspaces are working fine. Others yield this error.

npm@8.1.2 or npm@8.3.2
node@16.13.1

@nlf
Copy link
Contributor

nlf commented May 31, 2022

instead of npm install ./pkg-a -w ./pkg-b try npm install pkg-a -w pkg-b

using a ./ as the lead of the package to install (i.e. ./pkg-a) causes npm to see it as a file: dependency rather than a symlink, which is why you're seeing strange behavior here. removing the leading ./ will add it as a regular dependency and will correctly resolve to the symlink.

this is a thing we should probably smooth over for users, though, as that's pretty confusing.

@nlf
Copy link
Contributor

nlf commented May 31, 2022

i'm going to close this as a duplicate of #3847 and move the conversation there

@nlf nlf closed this as not planned Won't fix, can't repro, duplicate, stale May 31, 2022
@solsson
Copy link

solsson commented Dec 2, 2022

I think that this issue and #3847 should be de-duplicated. #3847 might have been fixed in #5350 but the error message is slightly different. Should this issue be reopened, as it represents Cannot set properties of null (setting 'dev')?

@wcardosodev
Copy link

I'm also getting this error when trying to run npm link ../myapp/node_modules/react from my library to my app, tried using both node @16.13.1 and @18.15.0

@sid2364
Copy link

sid2364 commented Mar 23, 2023

Something else that helped me resolve this issue was just that the npm ci command was running (via Jenkins, in my case) from the wrong directory, and couldn't find the package-lock.json file. It was just a matter of running it from the right directory - since npm ci couldn't find the lock file.

@solsson
Copy link

solsson commented Mar 25, 2023

For our cases of this issue, delete node_modules and rerun npm install seems to be a reliable workaround.

@nathanpovo
Copy link

nathanpovo commented Apr 6, 2023

I was getting this error when trying to link my react package to locally test a package. I was following the instructions here

For our cases of this issue, delete node_modules and rerun npm install seems to be a reliable workaround.

Could not get this workaround to work. I tested with node versions 18.14.2, 18.15.0, and 19.8.1.

What ended up working for me was to go to the package I wanted to test and override the react package installation in that package with the physical location of the installed react package of the app I was running.

Then, I could link to the package I needed to test and run the app without issues.

For example, given the following structure:

parent/
├─ package-to-test/
│  ├─ package.json
├─ my-react-app/
│  ├─ node_modules/
│  │  ├─ react/
│  ├─ package.json

Run the following commands:

cd ./parent/my-react-app
npm install

cd ../package-to-test
npm install
npm install ../my-react-app/node-modules/react

cd ../my-react-app
npm link ../my-react-app

npm start

@jric
Copy link

jric commented Jun 25, 2023

Thank you @nathanpovo , your answer helped me find my answer. I simply had to go to the linked package and install its dependencies. Then I could install the dependencies in my own package without getting this error. One thing is clear: This issue should be reopened so that a better error message could be provided.

@Clonkex
Copy link

Clonkex commented Jul 3, 2023

If anyone comes here trying to make a Shopify app by following the QR code example, I eventually discovered I had to run npm install in the root directory of the app first, and then npm install @shopify/react-form in the web/frontend directory. You may also need to remove node_modules folders and package-lock.json, I'm not sure.

I really wish this error would be updated to something more meaningful, because as it stands it's virtually impossible to figure out what you did wrong without endless googling.

I'll also mention issue #3901 since I don't see it mentioned here.

@rodrigogsqquid
Copy link

@Clonkex aaaaand you basically just saved my life. Thank you so much for being as detailed as to include my exact same case.

Cheers!

@himanshurajora
Copy link

@Clonkex Thanks, Your solution was really helpful. I had a package.json at the root and also at packages/app/package.json.
Though in my case I realize that I didn't even need the packages at root anymore. So I deleted both the node_modules and package.* from root. And then perfectly installed the packages for app.

@nalanj
Copy link

nalanj commented Aug 11, 2023

In case anyone else hits this, I had this issue come up after deleting a package in my monorepo. I had a lingering dependency to that now deleted package, and got this error any time I tried to install any additional packages to that workspace. Deleting the lingering dependency in my package.json solved it.

@OnkelTem
Copy link

After I deleted one package from ' packages ', I ran into the same thing in a monorepo. All I needed to do was delete node_modules/ and package-lock.json.

@solsson
Copy link

solsson commented Aug 31, 2023

@nlf Since you closed the issue in #4064 (comment), would you (or some other maintainer) consider re-opening, based on the argument above? There seems to be reliable workarounds, and I think that people are more likely to find them if the issue isn't marked as closed.

@realtril
Copy link

I was able to get around this by doing a npm ci

This one is working for me as well. But the problem is that I have to install the modules globally. Is there any solution on it?

@janis-veinbergs
Copy link

Had a monorepo, some projects had slightly different versions for packages that were symlinked from child project to workspace root (poor mans nohoist within postinstall). Dunno which action certainly resolved the issue, but from the problematic child package:

  1. Remove-Item ./node_modules/symlinked-package
  2. Updated all references to package to use specific single version. Actually I used newer, so I also did an update for package
  3. npm install

I also briefly removed my postinstall step ("postinstall": "symlink-dir ../../node_modules/pcf-scripts node_modules/pcf-scripts && symlink-dir ../../node_modules/pcf-start node_modules/pcf-start",) that does the symlink stuff. But I put it right back and did another npm install and it works. Pushing to build server also works (but I also removed symlink there manually). So I suspect it may have been the incosistent versions for package, but dunno.

@juxnpxblo
Copy link

juxnpxblo commented Nov 28, 2023

so I had a local react-library-app and a react-consumer-app and the lib was being consumed by npm link, and because both apps had their own react installed on their node_modules, I was getting a react error Warning: Invalid hook call You might have more than one copy of React in the same app

tried to npm link the react installation from one app to another then got this error npm ERR! Cannot set properties of null (setting 'dev')

inspired by @nathanpovo fix all I just did was a npm install <react-library-app_dir>/node_modules/react on react-consumer-app directory and it started to work

@szilardd
Copy link

For me the error was shown after trying to do a npm link ../myapp/node_modules/react. The issue was that this link already existed. npm link stores links globally, to reuse them across multiple projects.

I ran npm root -g to find the global node_modules folder, then deleted the link from there and after that it worked.

@justgeek
Copy link

For me the error was shown after trying to do a npm link ../myapp/node_modules/react. The issue was that this link already existed. npm link stores links globally, to reuse them across multiple projects.

I ran npm root -g to find the global node_modules folder, then deleted the link from there and after that it worked.

Worked perfectly for me. Thanks a lot

@ShaMan123
Copy link

Happened to me because I didn't initialize a workspace and tried to npm i in it
https://docs.npmjs.com/cli/v10/using-npm/workspaces#getting-started-with-workspaces

@maslade
Copy link

maslade commented Apr 16, 2024

I encountered this when accidentally committing a "file:../projectX" dependency that I was using temporarily for local development. Easy fix once I deciphered the confusing error message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release
Projects
None yet
Development

No branches or pull requests