nrwl / nx

Smart Monorepos ยท Fast CI
https://nx.dev
MIT License
23.66k stars 2.36k forks source link

Migrate CRA app to integrated monorepo #17421

Closed zanatoshi closed 1 year ago

zanatoshi commented 1 year ago

Current Behavior

On a CRA react app repository, migrating to an integrated NX repo with Vite is failing. image

Expected Behavior

Expect to migrate the app to vite in a NX monorepo

GitHub Repo

No response

Steps to Reproduce

  1. NX_VERBOSE_LOGGING=true npx nx@latest init --integrated --force --nxCloud

Nx Report

N/A

Failure Logs

>  NX   ๐Ÿณ Nx initialization

 >  NX   Let's create a new workspace [https://nx.dev/getting-started/intro]

 >  NX   Creating your v16.3.2 workspace.

   To make sure the command works reliably in all environments, and that the preset is applied correctly,
   Nx will run "yarn install" several times. Please wait.

โœ” Installing dependencies with yarn
โœ– Creating your workspace in temp-workspace

 >  NX   Failed to create a workspace.

   Error: error Command failed with exit code 1.

   Stack: CreateNxWorkspaceError: error Command failed with exit code 1.

    at /home/florian/.npm/_npx/505743838affa773/node_modules/create-nx-workspace/src/utils/child-process-utils.js:38:21
    at ChildProcess.exithandler (node:child_process:427:5)
    at ChildProcess.emit (node:events:513:28)
    at maybeClose (node:internal/child_process:1091:16)
    at ChildProcess._handle.onexit (node:internal/child_process:302:5)

nx init

Adds Nx to any type of workspace. It installs nx, creates an nx.json configuration file and optionally sets up distributed caching. For
more info, check https://nx.dev/recipes/adopting-nx.

Options:
  --help         Show help                                                                                                      [boolean]
  --version      Show version number                                                                                            [boolean]
  --nxCloud      Set up distributed caching with Nx Cloud.                                                                      [boolean]
  --interactive  When false disables interactive input prompts for options.                                     [boolean] [default: true]
  --integrated   Migrate to an Nx integrated layout workspace. Only for Angular CLI workspaces and CRA projects.
                                                                                                               [boolean] [default: false]
  --addE2e       Set up Cypress E2E tests in integrated workspaces. Only for CRA projects.                     [boolean] [default: false]
  --force        Force the migration to continue and ignore custom webpack setup or uncommitted changes. Only for CRA projects.
                                                                                                               [boolean] [default: false]
  --vite         Use Vite as the bundler. Only for CRA projects.                                                [boolean] [default: true]

Error: Command failed: npx -y create-nx-workspace@latest temp-workspace --appName=identity-frontend --preset=react-monorepo --style=css --bundler=vite --packageManager=yarn --nxCloud
    at checkExecSyncError (node:child_process:885:11)
    at execSync (node:child_process:957:15)
    at createTempWorkspace (/home/florian/.npm/_npx/f948e921c5898768/node_modules/nx/src/command-line/init/implementation/react/index.js:132:34)
    at /home/florian/.npm/_npx/f948e921c5898768/node_modules/nx/src/command-line/init/implementation/react/index.js:87:9
    at Generator.next (<anonymous>)
    at /home/florian/.npm/_npx/f948e921c5898768/node_modules/tslib/tslib.js:167:75
    at new Promise (<anonymous>)
    at Object.__awaiter (/home/florian/.npm/_npx/f948e921c5898768/node_modules/tslib/tslib.js:163:16)
    at reorgnizeWorkspaceStructure (/home/florian/.npm/_npx/f948e921c5898768/node_modules/nx/src/command-line/init/implementation/react/index.js:86:20) {
  status: 1,
  signal: null,
  output: [ null, null, null ],
  pid: 99574,
  stdout: null,
  stderr: null
}

Operating System

Additional Information

This is a private project, can't give a repository link. Could not reproduce in a public repository. Anyway I can debug this somehow ?

Also tried on macOS

xiongemi commented 1 year ago

These steps failed to create a temp-workspace in your repo. I don't see why it would. it does the same thing where you run npx -y create-nx-workspace@latest temp-workspace --appName=identity-frontend --preset=react-monorepo --style=css --bundler=vite --packageManager=yarn --nxCloud at workspace root. it should be same behaviour for private vs public repo.

zanatoshi commented 1 year ago

If I run this command NX_VERBOSE_LOGGING=true npx -y create-nx-workspace@latest temp-workspace --appName=identity-frontend --preset=react-monorepo --style=css --bundler=vite --packageManager=yarn , I have this result:

 >  NX   Failed to create a workspace.

   Error: error Command failed with exit code 1.

   Stack: CreateNxWorkspaceError: error Command failed with exit code 1.

    at /home/florian/.npm/_npx/505743838affa773/node_modules/create-nx-workspace/src/utils/child-process-utils.js:38:21
    at ChildProcess.exithandler (node:child_process:427:5)
    at ChildProcess.emit (node:events:513:28)
    at maybeClose (node:internal/child_process:1091:16)
    at ChildProcess._handle.onexit (node:internal/child_process:302:5)

If I try in an empty folder, it works.

Let me know if you need any other info.

xiongemi commented 1 year ago

@zanatoshi is there already a temp-workspace folder in your workspace? if so could you delete the folder and run the command again NX_VERBOSE_LOGGING=true npx -y create-nx-workspace@latest temp-workspace --appName=identity-frontend --preset=react-monorepo --style=css --bundler=vite --packageManager=yarn? if this does not work, could you paste the yarn-error.log under temp-workspace?

TNAJanssen commented 1 year ago

I have the same issue here

TNAJanssen commented 1 year ago

https://github.com/yarnpkg/berry/issues/625 <- is the issue

xiongemi commented 1 year ago

is it an issue with yarn? when there is yarn.lock already in the workspace, there is some issue doing yarn install for create-nx-workspace? would delete yarn.lock solve this issue then? when run nx init it will override your package.json anyway.

zanatoshi commented 1 year ago

So if I delete yarn.lock, then it use npm instead which go further than yarn but still failed because of missing npm lock file.

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! ๐Ÿ™

github-actions[bot] commented 1 year ago

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.