nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.63k stars 2.36k forks source link

Can't move an angular package into a subfolder #15292

Closed DmitryEfimenko closed 1 year ago

DmitryEfimenko commented 1 year ago

Current Behavior

Attempting to move an Angular project results in an error: Cannot read properties of null (reading 'replace')

Expected Behavior

The command should succeed.

GitHub Repo

https://github.com/DmitryEfimenko/ngspot

Steps to Reproduce

  1. Clone the repo
  2. Update nx to latest: npm run nx -- migrate next (and follow normal migration steps)
  3. run npm run nx -- g @nrwl/angular:move --project ng-superclass --destination ./ng-superclass/package --dry-run
  4. observe an error

When the same command is run with --verbose option, the following error is shown:

TypeError: Cannot read properties of null (reading 'toString')
    at FsTree.read (C:\Source\ngspot-nx\node_modules\nx\src\generators\tree.js:24:39)
    at updateProjectRootFiles (C:\Source\ngspot-nx\node_modules\@nrwl\workspace\src\generators\move\lib\update-project-root-files.js:38:33)
    at C:\Source\ngspot-nx\node_modules\@nrwl\workspace\src\generators\move\move.js:30:64
    at Generator.next (<anonymous>)
    at C:\Source\ngspot-nx\node_modules\tslib\tslib.js:167:75
    at new Promise (<anonymous>)
    at Object.__awaiter (C:\Source\ngspot-nx\node_modules\tslib\tslib.js:163:16)
    at moveGenerator (C:\Source\ngspot-nx\node_modules\@nrwl\workspace\src\generators\move\move.js:22:20)
    at C:\Source\ngspot-nx\node_modules\@nrwl\angular\src\generators\move\move.js:18:46
    at Generator.next (<anonymous>)

 >  NX   Cannot read properties of null (reading 'replace')

Nx Report

npm  : 8.19.2

   nx                      : 15.8.0-beta.7
   @nrwl/js                : 15.8.0-beta.7
   @nrwl/jest              : 15.8.0-beta.7
   @nrwl/linter            : 15.8.0-beta.7
   @nrwl/workspace         : 15.8.0-beta.7
   @nrwl/angular           : 15.8.0-beta.7
   @nrwl/cli               : 15.8.0-beta.7
   @nrwl/cypress           : 15.8.0-beta.7
   @nrwl/devkit            : 15.8.0-beta.7
   @nrwl/eslint-plugin-nx  : 15.8.0-beta.7
   @nrwl/tao               : 15.8.0-beta.7
   @nrwl/webpack           : 15.8.0-beta.7
   @nrwl/nx-cloud          : 15.1.1
   typescript              : 4.9.5
   ---------------------------------------
   Community plugins:
   @jscutlery/semver   : 2.29.3
   @ngneat/spectator   : 13.0.0
   angular-cli-ghpages : 1.0.5
   ng-mocks            : 14.5.1

Failure Logs

No response

Additional Information

Moving a non-angular project into a subfolder works as expected.

leosvelperez commented 1 year ago

@DmitryEfimenko I couldn't reproduce the issue. I wonder if it's OS-specific. Are you running on Windows? The nx report is cut at the top and I only see the package manager, not the OS.

DmitryEfimenko commented 1 year ago

I am indeed on Windows 11

leosvelperez commented 1 year ago

Cool, I think I know what's going on. I'll reproduce it on a VM just to be sure and push a fix. Thanks for the info!

leosvelperez commented 1 year ago

I could not reproduce the issue on a Windows VM either 🤔 I cloned the repo, migrated it to next and ran the same command pasted in the reproduction steps. Are you having the issue in a different branch? Or do you have any changes that are not pushed?

DmitryEfimenko commented 1 year ago

I do have changes that are not pushed. I didn't think they would affect anything. Let me try and create a clean repro - perhaps on a different branch. Thanks for looking into it and I'm sorry for bad repro. I'll update here with clean repro shortly

leosvelperez commented 1 year ago

No worries! It's currently late for me, so if you leave updated details, I'll have a look tomorrow.

DmitryEfimenko commented 1 year ago

Could you please see if you can reproduce on branch feat/super?

  1. clone
  2. git checkout feat/super
  3. npm install --force
  4. npm run nx -- g @nrwl/angular:move --project ng-superclass --destination ./ng-superclass/package --dry-run

I've run these steps on a different computer (also Windows, but version 10) that didn't have this repository. Interestingly, I got a different error:

>  NX   Cannot find packages\ng-superclass\project.json

Error: Cannot find packages\ng-superclass\project.json
    at readJson (C:\source\ngspot\node_modules\@nrwl\angular\node_modules\nx\src\generators\utils\json.js:14:15)
    at C:\source\ngspot\node_modules\@nrwl\angular\node_modules\nx\src\generators\utils\project-configuration.js:120:119
    at buildProjectsConfigurationsFromGlobs (C:\source\ngspot\node_modules\@nrwl\angular\node_modules\nx\src\config\workspaces.js:479:35)
    at readAndCombineAllProjectConfigurations (C:\source\ngspot\node_modules\@nrwl\angular\node_modules\nx\src\generators\utils\project-configuration.js:120:66)
    at readProjectConfiguration (C:\source\ngspot\node_modules\@nrwl\angular\node_modules\nx\src\generators\utils\project-configuration.js:80:25)
    at updateModuleName (C:\source\ngspot\node_modules\@nrwl\angular\src\generators\move\lib\update-module-name.js:17:59)
    at C:\source\ngspot\node_modules\@nrwl\angular\src\generators\move\move.js:19:51
    at Generator.next (<anonymous>)
    at fulfilled (C:\source\ngspot\node_modules\tslib\tslib.js:164:62)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
leosvelperez commented 1 year ago

@DmitryEfimenko it looks like a hoisting issue with npm and those beta versions. Using --legacy-peer-deps instead of force works (having deleted node_modules first) and also using another package manager like Yarn.

That said, the stable release 15.8.0 is now out. Migrating the workspace to latest make the error go away.

I'm going to close the issue since it's resolved in latest. Please make sure to migrate to latest.

DmitryEfimenko commented 1 year ago

I updated nx deps to the latest (15.8.1) and it worked... somewhat.

I created a new issue to describe the bugs I observed: https://github.com/nrwl/nx/issues/15354

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.