[英]Cannot find module 'nx/src/config/workspaces' on creating a React app on existing Nx project
I am getting the following error and I add the react app to the already existing Nx project on my system:我收到以下错误,并将 React 应用程序添加到我系统上已有的 Nx 项目中:
Require stack:
- C:\Users\HP\OneDrive\Documents\amagi-qtc\node_modules\@nrwl\devkit\index.js
- C:\Users\HP\OneDrive\Documents\amagi-qtc\node_modules\@nrwl\react\src\utils\lint.js
- C:\Users\HP\OneDrive\Documents\amagi-qtc\node_modules\@nrwl\react\src\generators\application\application.js
- C:\Users\HP\OneDrive\Documents\amagi-qtc\node_modules\nx\src\shared\workspace.js
- C:\Users\HP\OneDrive\Documents\amagi-qtc\node_modules\nx\src\cli\init-local.js
- C:\Users\HP\OneDrive\Documents\amagi-qtc\node_modules\nx\bin\nx.js
- C:\Users\HP\AppData\Roaming\npm\node_modules\@nrwl\cli\node_modules\nx\bin\nx.js
- C:\Users\HP\AppData\Roaming\npm\node_modules\@nrwl\cli\bin\nx.js
I did to install react in a nx project我确实在 nx 项目中安装了 react
yarn add -D @nrwl/react
But when I run this command:但是当我运行这个命令时:
nx g @nrwl/react:app my-new-app
It gives me the above error.它给了我上述错误。
The issue could have happened due to the project not having the latest NX version packages.该问题可能是由于项目没有最新的 NX 版本包而发生的。
Ensure the nx cli is installed in your local project, yarn add -D @nrwl/cli
.确保 nx cli 安装在您的本地项目中,
yarn add -D @nrwl/cli
。
Run nx migrate latest
from your project to do the upgrades, it will update your package.json file.从您的项目运行
nx migrate latest
进行升级,它将更新您的 package.json 文件。
You can review the changes made to package.json and run yarn
to install them.您可以查看对 package.json 所做的更改并运行
yarn
来安装它们。
Finally, you have to run the migrations by running nx migrate --run-migrations
.最后,您必须通过运行
nx migrate --run-migrations
来运行迁移。
Reference: https://nx.dev/using-nx/updating-nx#updating-nx参考: https ://nx.dev/using-nx/updating-nx#updating-nx
If anyone stumbles upon this in 2023 and beyond here's the simple solution which worked for me.如果有人在 2023 年及以后偶然发现这个问题,这里有一个对我有用的简单解决方案。
node_modules
in entirety - rm -rf node_modules
node_modules
- rm -rf node_modules
npm install
, ensure you install the nx plugin package with the exact version of nx (As per package.json file.- npm install @nrwl/nx-plugin@<Exact version number>
npm install
后,确保安装 nx 插件 package 和 nx 的确切版本(根据 package.json 文件。- npm install @nrwl/nx-plugin@<Exact version number>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.