nrwl/add-nx

cra-to-nx attempts to edit project.json, but does not create it

kevinyaroch opened this issue · 13 comments

I've been attempting migrate a create-react-app project to Nx by running npx cra-to-nx, and everything appears to work until the script tries to add the CRA commands to workspace.json, at which point it throws this error:

ENOENT: no such file or directory, open '/Users/KevinYaroch/amount-repos/nx-test-app/temp-workspace/apps/nx-test-app/project.json'
Error: Command failed: npx nx g @nrwl/workspace:run-commands serve     --project nx-test-app     --command "node ../../node_modules/.bin/react-app-rewired start"     --cwd "apps/nx-test-app"
    at checkExecSyncError (child_process.js:643:11)
    at Object.execSync (child_process.js:679:15)
    at Object.addCRACommandsToWorkspaceJson (/Users/KevinYaroch/.config/yarn/global/node_modules/cra-to-nx/src/lib/add-cra-commands-to-nx.js:6:21)
    at Object.<anonymous> (/Users/KevinYaroch/.config/yarn/global/node_modules/cra-to-nx/src/lib/cra-to-nx.js:58:34)
    at Generator.next (<anonymous>)
    at /Users/KevinYaroch/.config/yarn/global/node_modules/cra-to-nx/node_modules/tslib/tslib.js:117:75
    at new Promise (<anonymous>)
    at Object.__awaiter (/Users/KevinYaroch/.config/yarn/global/node_modules/cra-to-nx/node_modules/tslib/tslib.js:113:16)
    at Object.createNxWorkspaceForReact (/Users/KevinYaroch/.config/yarn/global/node_modules/cra-to-nx/src/lib/cra-to-nx.js:36:20)
    at Object.<anonymous> (/Users/KevinYaroch/.config/yarn/global/node_modules/cra-to-nx/src/index.js:7:13)

I was able to replicate this with a newly created CRA app with the default settings, so I don't think anything in my existing app is causing this.

It looks like using project.json is the default in Nx 13, so I'm guessing that some of the commands called by cra-to-nx are using the Nx 12 behavior and some are using Nx 13?

[ETA: I should clarify that when I copied the backtrace above, I was using a local yarn install of cra-to-nx, but the result is the same if I run it using npx.]

I've got the same problem with npm [npx create-react-app].
App created with latest create-react-app results in error kevinyaroch mentioned.

Yep, I have the exact same problem. Tried with a completely new cra project.

I also faced this issue. Is there any solution?

Hey all! Apologies, I need to fix this but I do not have much time this week! I will get to it next week, or the week after, I promise :)

In the meantime, you can try using this guide and let me know if it works? I am really really sorry that you are having a bad experience with cra-to-nx, let me know if I can help in some other way, until I get the code fixed!

hey @mandarini, I followed Doing the migration manually steps and it also required project.json file in 4th step.
So I created project.json file in the app manually after that I run the command. It worked. :)
I think u need to update documentation as well.

Actually after create temp-workspace, the project.json is removed when copying existing cra project files.

can someone provide github repository with working example ?

Hi @Digital-Coder ! I'll try to provide something soon! Sorry for lingering on this so long!

The guide has been updated https://nx.dev/l/r/migration/migration-cra

Fix for the cra-to-nx package always being released soon (today).

The guide has been updated https://nx.dev/l/r/migration/migration-cra

Fix for the cra-to-nx package always being released soon (today).

4. Add CRA commands to workspace.json. Shouldnt we add these "serve, build" commands to project.json in each repository ?

Ah, the title needs to be updated. The steps are correct though.

Also, just published cra-to-nx@2.0.0 which fully supports Nx 13 and CRA 5. We detect whether you are using CRA 4 or 5 and apply the right changes.

We'll probably move to craco instead of react-app-rewired since the latter isn't active.

Thank you @jaysoo !!!!!