如何使用指定版本(^10.0.0)的Nx Workspace生成Angular项目?
I've run into this exact issue before when trying to lock in older Nx versions—let me walk you through the correct commands to make this work, and explain why your earlier attempts failed.
The Problem with Your Initial Commands
Your first command installed the 10.0.6 @nrwl/cli globally, but when using yarn create nx-workspace, it still pulls the latest version of the create-nx-workspace package by default, which overrides the global CLI version.
Your second attempt tried yarn create nx-workspace@10.0.6—this syntax doesn't work with yarn create; you can't append the version directly to the package name like that, which is why you got the "No such file or directory" error.
Correct Methods to Generate a 10.x Nx Workspace
Method 1: Use yarn create with the --package flag
This is the cleanest way to specify the exact version of create-nx-workspace to use:
yarn create nx-workspace myProject --style=scss --preset=empty --nx-cloud=false --cli=angular --package create-nx-workspace@10.0.6
The --package flag tells yarn to use the specific version of the create-nx-workspace package instead of the latest.
Method 2: Install the specific create-nx-workspace version globally first
If you prefer to have the CLI available globally afterward, install the exact version first, then run the creation command:
- Uninstall any existing global Nx CLI versions to avoid conflicts:
yarn global remove @nrwl/cli create-nx-workspace - Install the 10.0.6 version of
create-nx-workspace:yarn global add create-nx-workspace@10.0.6 - Run the workspace creation command normally:
create-nx-workspace myProject --style=scss --preset=empty --nx-cloud=false --cli=angular
Verify the Result
After running either method, open the generated package.json in your myProject folder. You should see dependencies like this (all 10.x versions):
"@angular/cli": "~10.0.0", "@nrwl/tao": "10.0.6", "@nrwl/cli": "10.0.6", "@nrwl/workspace": "10.0.6", "@types/node": "~14.0.0", "dotenv": "~8.2.0", "ts-node": "~8.10.2", "typescript": "~3.9.7", "prettier": "^2.0.5"
This ensures you're fully locked into the 10.x version ecosystem without any 12.x dependencies creeping in.
内容的提问来源于stack exchange,提问作者m4lt3

