nrwl / nx

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

NX Migrate from 14.8.4 fails on angular.json file conversion - Cannot create property 'name' on string 'libs/auth' #20633

Closed krstns closed 7 months ago

krstns commented 9 months ago

Current Behavior

I've tried running the migration:

nx migrate latest --from=nx@14.8.4
yarn
nx migrate --run-migrations --verbose

results in:

 >  NX   Failed to run 15-7-0-split-configuration-into-project-json-files from @nrwl/workspace. This workspace is NOT up to date!

 >  NX   Cannot create property 'name' on string 'libs/auth'

My angular.json file is v2:

{
  "version": 2,
  "projects": {
    "auth": "libs/auth",
[...]
}

Expected Behavior

Workspace migrated to latest nx.

GitHub Repo

No response

Steps to Reproduce

1.run the same commands on an nx 14.8.4 project with external and internal libraries.

Nx Report

report from before migration. after failed migration it's impossible to run any 'nx' commands.

>nx report

 >  NX   Report complete - copy this into the issue template

   Node : 18.19.0
   OS   : darwin arm64
   yarn : 1.22.19

   nx : 14.8.4
   @nrwl/angular : 14.8.4
   @nrwl/cypress : 14.8.4
   @nrwl/detox : Not Found
   @nrwl/devkit : 14.8.4
   @nrwl/esbuild : Not Found
   @nrwl/eslint-plugin-nx : 14.8.4
   @nrwl/expo : Not Found
   @nrwl/express : Not Found
   @nrwl/jest : 14.8.4
   @nrwl/js : 14.8.4
   @nrwl/linter : 14.8.4
   @nrwl/nest : Not Found
   @nrwl/next : Not Found
   @nrwl/node : Not Found
   @nrwl/nx-cloud : Not Found
   @nrwl/nx-plugin : Not Found
   @nrwl/react : Not Found
   @nrwl/react-native : Not Found
   @nrwl/rollup : Not Found
   @nrwl/schematics : Not Found
   @nrwl/storybook : 14.8.4
   @nrwl/web : Not Found
   @nrwl/webpack : 14.8.4
   @nrwl/workspace : 14.8.4
   typescript : 4.7.3
   ---------------------------------------
   Local workspace plugins:
   ---------------------------------------
   Community plugins:
         @fortawesome/angular-fontawesome: 0.11.1
         ng-extract-i18n-merge: 2.4.0

Failure Logs

>nx migrate --run-migrations --verbose

 >  NX   Running 'yarn' to make sure necessary packages are installed

yarn install v1.22.19
warning package.json: License should be a valid SPDX license expression
warning myproject@0.0.1: License should be a valid SPDX license expression
[1/4] 🔍  Resolving packages...
success Already up-to-date.
$ node ./decorate-angular-cli.js && ngcc --properties es2020 browser module main

 >  NX   Decoration of the Angular CLI is deprecated and will be removed in a future version

   Please replace usage of "ng <command>" in any scripts, particularly for CI, with "nx <command>"

 >  NX   Angular CLI has been decorated to enable computation caching.

==========================================

ALERT: As of Angular 16, "ngcc" is no longer required and not invoked during CLI builds. You are seeing this message because the current operation invoked the "ngcc" command directly. This "ngcc" invocation can be safely removed.

A common reason for this is invoking "ngcc" from a "postinstall" hook in package.json.

In Angular 17, this command will be removed. Remove this and any other invocations to prevent errors in later versions.

==========================================

✨  Done in 0.47s.
yarn run v1.22.19
warning package.json: License should be a valid SPDX license expression
$ /Users/krystian/projects/myproject/node_modules/.bin/nx migrate --run-migrations --verbose
warning package.json: License should be a valid SPDX license expression
$ /Users/krystian/projects/myproject/node_modules/.bin/nx _migrate --run-migrations --verbose

 >  NX   Running migrations from 'migrations.json'

 >  NX   Failed to run 15-7-0-split-configuration-into-project-json-files from @nrwl/workspace. This workspace is NOT up to date!

 >  NX   Cannot create property 'name' on string 'libs/auth'

TypeError: Cannot create property 'name' on string 'libs/auth'
    at toNewFormat (/Users/krystian/projects/myproject/node_modules/nx/src/adapter/angular-json.js:64:32)
    at convertToNxProjectGenerator (/Users/krystian/projects/myproject/node_modules/@nx/workspace/src/generators/convert-to-nx-project/convert-to-nx-project.js:34:53)
    at async splitConfigurationIntoProjectJsonFiles (/Users/krystian/projects/myproject/node_modules/@nx/workspace/src/migrations/update-15-7-0/split-configuration-into-project-json-files.js:7:5)
    at async runNxMigration (/Users/krystian/projects/myproject/node_modules/nx/src/command-line/migrate/migrate.js:1016:5)
    at async executeMigrations (/Users/krystian/projects/myproject/node_modules/nx/src/command-line/migrate/migrate.js:879:33)
    at async runMigrations (/Users/krystian/projects/myproject/node_modules/nx/src/command-line/migrate/migrate.js:964:37)
    at async /Users/krystian/projects/myproject/node_modules/nx/src/command-line/migrate/migrate.js:1033:13
    at async handleErrors (/Users/krystian/projects/myproject/node_modules/nx/src/utils/params.js:9:16)
    at async Object.handler (/Users/krystian/projects/myproject/node_modules/nx/src/command-line/migrate/command-object.js:26:43)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Command failed: yarn nx _migrate --run-migrations --verbose
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

 >  NX   Command failed: yarn nx migrate --run-migrations --verbose

Error: Command failed: yarn nx migrate --run-migrations --verbose
    at checkExecSyncError (node:child_process:890:11)
    at execSync (node:child_process:962:15)
    at runNxSync (/private/var/folders/5_/t03cfbb54pq6jvlk4g14hrlh0000gn/T/tmp-29922-ExlipWD4n4Um/node_modules/nx/src/utils/child-process.js:25:34)
    at runMigrations (/private/var/folders/5_/t03cfbb54pq6jvlk4g14hrlh0000gn/T/tmp-29922-ExlipWD4n4Um/node_modules/nx/src/command-line/migrate/migrate.js:939:39)
    at /private/var/folders/5_/t03cfbb54pq6jvlk4g14hrlh0000gn/T/tmp-29922-ExlipWD4n4Um/node_modules/nx/src/command-line/migrate/migrate.js:1033:19
    at async handleErrors (/private/var/folders/5_/t03cfbb54pq6jvlk4g14hrlh0000gn/T/tmp-29922-ExlipWD4n4Um/node_modules/nx/src/utils/params.js:9:16)
Command failed: /var/folders/5_/t03cfbb54pq6jvlk4g14hrlh0000gn/T/tmp-29922-ExlipWD4n4Um/node_modules/.bin/nx _migrate --run-migrations --verbose

Package Manager Version

No response

Operating System

Additional Information

No response

bstelljes commented 9 months ago

Do you have a workspace.json in root directory? I just tried the migration by myself and encountered the same problem as you. My workspace.json looked like this:

{
  "version": 2,
  "projects": {
    "ruder-challenge": "apps/ruder-challenge"
  }
}

and I've changed it to

{
  "version": 2,
  "projects": {
    "ruder-challenge": { "name": "ruder-challenge", "root": "apps/ruder-challenge" }
  }
}

After that the migration-script worked (and correctly removed the workspace.json)

krstns commented 9 months ago

@bstelljes thanks for the info. I don't have workspace.json. I do still have angular.json file. I would expect that this would be a part of the migration process.

krstns commented 9 months ago

I've tried converting the angular.json file on my own and run migrations again, but I didn't go too far with it. The next error I get is:

[...]
  UPDATE apps/core/project.json
---------------------------------------------------------

 >  NX   Failed to run block-template-entities from @angular/core. This workspace is NOT up to date!

 >  NX   import_typescript3.default.getDecorators is not a function

TypeError: import_typescript3.default.getDecorators is not a function
    at /Users/krystian/projects/myproject/node_modules/@angular/core/schematics/migrations/block-template-entities/bundle.js:25408:57
    at walk (/Users/krystian/projects/myproject/node_modules/@angular/core/schematics/migrations/block-template-entities/bundle.js:25480:7)
    at visitNodes (/Users/krystian/projects/myproject/node_modules/typescript/lib/typescript.js:30672:30)
    at Object.forEachChild (/Users/krystian/projects/myproject/node_modules/typescript/lib/typescript.js:30951:24)
    at NodeObject.forEachChild (/Users/krystian/projects/myproject/node_modules/typescript/lib/typescript.js:163979:23)
    at forEachClass (/Users/krystian/projects/myproject/node_modules/@angular/core/schematics/migrations/block-template-entities/bundle.js:25478:14)
    at analyze (/Users/krystian/projects/myproject/node_modules/@angular/core/schematics/migrations/block-template-entities/bundle.js:25406:3)
    at runBlockTemplateEntitiesMigration (/Users/krystian/projects/myproject/node_modules/@angular/core/schematics/migrations/block-template-entities/bundle.js:25505:5)
    at SchematicImpl.<anonymous> (/Users/krystian/projects/myproject/node_modules/@angular/core/schematics/migrations/block-template-entities/bundle.js:25496:7)
    at Generator.next (<anonymous>)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Command failed: yarn nx _migrate --run-migrations --verbose
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

 >  NX   Command failed: yarn nx migrate --run-migrations --verbose

Error: Command failed: yarn nx migrate --run-migrations --verbose
    at checkExecSyncError (node:child_process:890:11)
    at execSync (node:child_process:962:15)
    at runNxSync (/private/var/folders/5_/t03cfbb54pq6jvlk4g14hrlh0000gn/T/tmp-44701-2G7qp9hGhAQl/node_modules/nx/src/utils/child-process.js:25:34)
    at runMigrations (/private/var/folders/5_/t03cfbb54pq6jvlk4g14hrlh0000gn/T/tmp-44701-2G7qp9hGhAQl/node_modules/nx/src/command-line/migrate/migrate.js:940:39)
    at /private/var/folders/5_/t03cfbb54pq6jvlk4g14hrlh0000gn/T/tmp-44701-2G7qp9hGhAQl/node_modules/nx/src/command-line/migrate/migrate.js:1034:19
    at async handleErrors (/private/var/folders/5_/t03cfbb54pq6jvlk4g14hrlh0000gn/T/tmp-44701-2G7qp9hGhAQl/node_modules/nx/src/utils/params.js:9:16)
Command failed: /var/folders/5_/t03cfbb54pq6jvlk4g14hrlh0000gn/T/tmp-44701-2G7qp9hGhAQl/node_modules/.bin/nx _migrate --run-migrations --verbose
tigersoftdev commented 9 months ago

@krstns try deleting angular.json file. It looks like it's not needed in newer versions.

gary-menzel commented 7 months ago

In my case, I got far enough (after making those changes to create the object for each workspace) that the migration actually deleted the workspace.json completely. I was going from V15 to latest. I still have other errors to resolve though.

krstns commented 7 months ago

I was able to come back to this project and this issue now. I have reverted all the changes made before and decided to do it differently. Instead of making migration to latest I started to go one by one. so first i ran: nx migrate 15 It was only an update of the nx package without any migrations. so far so good. Then: nx migrate 16 This time it updated the nx package and created migrations. The first migration was the separation of angular.json contents into specific project files. Just ran the migration and it went fine.

So my suggestion to anyone struggling with it - go one by one.

leosvelperez commented 7 months ago

Thanks for reporting this!

@krstns as you've discovered, it's actually recommended to migrate one major version at a time. This is particularly more important for Angular projects. The @angular/core package only keeps migrations for one major version. The Angular CLI doesn't support updating multiple major versions at a time, and therefore, their packages only contain migrations for any given current major version.

So, migrating over multiple major versions would lead to missing migrations and some other potential issues. It looks like you were able to solve the issue, so I'm going to close it. If someone else is still facing issues after following the above advise, please create a new issue and provide a reproduction so we can properly troubleshoot it.

github-actions[bot] commented 6 months 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.