8

I am getting the following error and I add the react app to the already existing Nx project on my system:

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

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.

Masudha Meher
  • 93
  • 1
  • 1
  • 7

3 Answers3

16

The issue could have happened due to the project not having the latest NX version packages.

Ensure the nx cli is installed in your local project, yarn add -D @nrwl/cli.

Run nx migrate latest from your project to do the upgrades, it will update your package.json file.

You can review the changes made to package.json and run yarn to install them.

Finally, you have to run the migrations by running nx migrate --run-migrations.

Reference: https://nx.dev/using-nx/updating-nx#updating-nx

kaoskeya
  • 1,071
  • 6
  • 12
4

If anyone stumbles upon this in 2023 and beyond here's the simple solution which worked for me.

  • Remove node_modules in entirety - rm -rf node_modules
  • Delete package-lock file. Sometimes nx can update few entries here which can cause issues when the app is started.
  • 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>
SeaWarrior404
  • 3,811
  • 14
  • 43
  • 65
  • 1
    with nx version: 16.6.0, I did remove, reinstall node_modules, and delete package-lock.json, but no need to install the nx-plugin. – Woden Aug 06 '23 at 04:24
0

The real solution is,

  1. Identify the Nx version you want to use, say v13.
  2. Install it locally via npm install --save-dev nx@13
codef0rmer
  • 10,284
  • 9
  • 53
  • 76