npm ERR! Cannot set properties of null (setting 'dev')
Problem
Is there an existing issue for this? - [X] I have searched the existing issues This issue exists in the latest npm version - [X] 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 [code block]
Error Output
Error: Cannot set properties of null (setting 'dev')
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Fix npm workspace installation error
The error 'Cannot set properties of null (setting 'dev')' occurs when npm attempts to set properties on a null reference during the installation of a package from one workspace to another. This can happen if the workspace configuration is not properly set up or if there are issues with the package.json files in the workspaces.
Awaiting Verification
Be the first to verify this fix
- 1
Check workspace configuration
Ensure that the workspaces are correctly defined in the root package.json file. The 'workspaces' field should include the paths to the packages.
json{ "name": "foo", "version": "1.0.0", "private": true, "workspaces": ["pkg-a", "pkg-b"] } - 2
Validate package.json files
Check that both pkg-a and pkg-b have valid package.json files with necessary fields like 'name', 'version', and 'main'. Ensure there are no syntax errors.
json{ "name": "pkg-a", "version": "1.0.0", "main": "index.js" } - 3
Clear npm cache
Sometimes, npm cache issues can lead to unexpected errors. Clear the npm cache to ensure a fresh start.
bashnpm cache clean --force - 4
Reinstall dependencies
After validating the configuration and clearing the cache, run npm install again from the root directory to reinstall dependencies across all workspaces.
bashnpm install - 5
Test installation
Try to install pkg-a in pkg-b again to verify that the error has been resolved. Use the command: npm install ./pkg-a -w pkg-b.
bashnpm install ./pkg-a -w pkg-b
Validation
Confirm that the installation completes without errors and that pkg-b can successfully reference pkg-a. Check the node_modules directory in pkg-b to ensure pkg-a is installed.
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep