[英]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.