[英]Cannot find module 'nx/src/config/workspaces' on creating a React app on existing Nx project
我收到以下错误,并将 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
我确实在 nx 项目中安装了 react
yarn add -D @nrwl/react
但是当我运行这个命令时:
nx g @nrwl/react:app my-new-app
它给了我上述错误。
该问题可能是由于项目没有最新的 NX 版本包而发生的。
确保 nx cli 安装在您的本地项目中, yarn add -D @nrwl/cli
。
从您的项目运行nx migrate latest
进行升级,它将更新您的 package.json 文件。
您可以查看对 package.json 所做的更改并运行yarn
来安装它们。
最后,您必须通过运行nx migrate --run-migrations
来运行迁移。
参考: https ://nx.dev/using-nx/updating-nx#updating-nx
如果有人在 2023 年及以后偶然发现这个问题,这里有一个对我有用的简单解决方案。
node_modules
- rm -rf node_modules
npm install
后,确保安装 nx 插件 package 和 nx 的确切版本(根据 package.json 文件。- npm install @nrwl/nx-plugin@<Exact version number>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.