Karsami's Space
open main menu

Fix Nx missing dependencies

/ 1 min read

If you use nx in Mac, Window and Linux at the same time, you will encounter one of these problems:

  • Cannot find module @nx/nx-darwin-x64
  • Cannot find module @nx/nx-darwin-arm64
  • Cannot find module @nx/nx-linux-x64-gnu
  • Cannot find module @nx/nx-win32-x64-msvc

To fix this problem, you need to make these dependencies is optional

// package.json
"dependencies": {
  //..
}
"devDependencies": {
  //..
},
"optionalDependencies": {
  "@nx/nx-darwin-arm64": "<your-version>",
  "@nx/nx-darwin-x64": "<your-version>",
  "@nx/nx-linux-x64-gnu": "<your-version>",
  "@nx/nx-win32-x64-msvc": "<your-version>"
}
rm -rf node_modules
# remove your lock file (package-lock.json or yarn.lock,...)
rm yarn.lock
# reinstall dependencies
npm install --include=optional
# or (recommend)
yarn