简体   繁体   English

在现有 Nx 项目上创建 React 应用程序时找不到模块“nx/src/config/workspaces”

[英]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 年及以后偶然发现这个问题,这里有一个对我有用的简单解决方案。

  • Remove node_modules in entirety - rm -rf node_modules完全删除node_modules - rm -rf node_modules
  • Delete package-lock file.删除包锁定文件。 Sometimes nx can update few entries here which can cause issues when the app is started.有时 nx 可以在这里更新一些条目,这可能会在应用程序启动时导致问题。
  • Once you rerun 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.

相关问题 无法在 NX-jsx 中提供 React 应用程序当前未启用 - Cannot serve React app in NX-jsx is not currently enabled 在 angular nx 项目中导入 JavaScript 模块 - import JavaScript module in angular nx project React Native 错误找不到模块'metro-config/src/defaults/blacklist' - React Native Error Cannot find module 'metro-config/src/defaults/blacklist' 在 expo react-native 项目中找不到模块“metro/src/lib/TerminalReporter” - Cannot find module 'metro/src/lib/TerminalReporter' in expo react-native project 如何在 Nx monorepo 内的 Nextjs 应用程序中使用 React-Native 组件 - How to use React-Native components in a Nextjs App inside an Nx monorepo 创建反应应用程序时出现此错误:找不到模块&#39;./lib/pack.js&#39; - When creating react app this error appears: Cannot find module './lib/pack.js' 找不到模块&#39;../dist/ngfactory/src/app/app.server.module.ngf actory&#39;。 角度cli - Cannot find module '../dist/ngfactory/src/app/app.server.module.ngf actory'. angular cli React Native 无法 npx init 项目,找不到模块错误 - React Native cannot npx init project, cannot find module error Angular v13 带 nx 测试的玩笑 - 语法错误:无法在 Runtime.createScriptFromCode 的模块外使用导入语句 - Angular v13 Jest with nx test - SyntaxError: Cannot use import statement outside a module at Runtime.createScriptFromCode 错误 - 找不到模块“config” - Error - Cannot find module 'config'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM