nrwl / nx

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

Unable to determine 'tsconfig.json' file in workspace config. #9280

Closed chriscurnow closed 2 years ago

chriscurnow commented 2 years ago

Current Behavior

I just rannx migrate --run-migrations

(I had just previously run nx migrate latest && npm i && nx migrate --run-migrations but it was missing a couple of dependencies โ€“

However under

Running migration migration-v13

For every many of my projects it said it was skipping them. For example

Skipping migration for project shared-util. Unable to determine 'tsconfig.json' file in workspace config.

Expected Behavior

Migrations works for every project

Steps to Reproduce

I'm guessing this is specific to my workspace so apart from the steps above I don't think I can create something that will reproduce the error.

Failure Logs

I'm not sure what I could provide more than what I have.

Environment

Node : 14.17.1 OS : darwin x64 npm : 7.20.0

nx : 13.8.7 @nrwl/angular : 13.8.7 @nrwl/cli : 13.8.7 @nrwl/cypress : 13.8.7 @nrwl/detox : undefined @nrwl/devkit : 13.8.7 @nrwl/eslint-plugin-nx : 13.8.7 @nrwl/express : undefined @nrwl/jest : 13.8.7 @nrwl/js : undefined @nrwl/linter : 13.8.7 @nrwl/nest : undefined @nrwl/next : undefined @nrwl/node : undefined @nrwl/nx-cloud : undefined @nrwl/react : undefined @nrwl/react-native : undefined @nrwl/schematics : undefined @nrwl/storybook : 13.8.7 @nrwl/tao : 13.8.7 @nrwl/web : undefined @nrwl/workspace : 13.8.7 typescript : 4.5.5 rxjs : 6.6.7


Community plugins: @angular-material-extensions/password-strength: 8.2.1 @angular/animations: 13.2.6 @angular/cdk: 13.2.6 @angular/common: 13.2.6 @angular/compiler: 13.2.6 @angular/core: 13.2.6 @angular/fire: 7.1.1 @angular/forms: 13.2.6 @angular/material: 13.2.6 @angular/material-luxon-adapter: 13.0.2 @angular/material-moment-adapter: 13.1.1 @angular/platform-browser: 13.2.6 @angular/platform-browser-dynamic: 13.2.6 @angular/router: 13.2.6 @ngrx/component-store: 13.0.2 @ngrx/effects: 13.0.2 @ngrx/entity: 13.0.2 @ngrx/router-store: 13.0.2 @ngrx/store: 13.0.2 @angular-devkit/build-angular: 13.2.6 @angular/compiler-cli: 13.2.6 @angular/language-service: 13.2.6 @ngrx/schematics: 13.0.2 @ngrx/store-devtools: 13.0.2

AgentEnder commented 2 years ago

Angular seems to rely on having tsconfig specified under the build target in your projects. Nx doesn't require this (and angular doesn't either for the build), but the migrations skip if it cannot find it.

Unfortunately, this is a case where you'll have to add that to the build target for the migrations to have an effect.

@Coly010 can jump in if I misspoke on this, but I think that's correct ๐Ÿ˜„.

chriscurnow commented 2 years ago

Thanks @AgentEnder, that does the trick.๐Ÿ™

I never would have found that myself.๐Ÿ˜€

Coly010 commented 2 years ago

@AgentEnder Is correct. There are some circumstances where schematics from Angular are trying to look for things that are potentially out of our control to patch. Glad it wasn't too hard to get it working :)

flensrocker commented 2 years ago

What exactly have I to do to get the migrations applied? In my workspace the migrations of Angular Material and CDK are skipped for all libraries.

In my projects my build targets look like this:

    "build": {
      "executor": "@nrwl/angular:package",
      "outputs": ["dist/libs/core/error"],
      "options": {
        "project": "libs/core/error/ng-package.json"
      },
      "configurations": {
        "production": {
          "tsConfig": "libs/core/error/tsconfig.lib.prod.json"
        },
        "development": {
          "tsConfig": "libs/core/error/tsconfig.lib.json"
        }
      },
      "defaultConfiguration": "production"
    },
flensrocker commented 2 years ago

Ok, I figured out that where I have to add that extra tsConfig:

    "build": {
      "executor": "@nrwl/angular:package",
      "outputs": ["dist/libs/core/error"],
      "options": {
=>      "tsConfig": "libs/core/error/tsconfig.lib.json",
        "project": "libs/core/error/ng-package.json"
      },
      "configurations": {
        "production": {
          "tsConfig": "libs/core/error/tsconfig.lib.prod.json"
        },
        "development": {
          "tsConfig": "libs/core/error/tsconfig.lib.json"
        }
      },
      "defaultConfiguration": "production"
    },

Is there an easy way to do it for all the libs in a workspace?

Is there some setting, so that newly generated projects have this already included?

Or is there any other fix I can use?

Thank you!

NicholaAlkhouri commented 2 years ago

@Coly010 @AgentEnder thank you guys, but what about the non-buildable libraries, we don't have "build" target for those libraries, and they are all skipped during the migration.

AgentEnder commented 2 years ago

I think it looks at the test target as well, so you can try adding it there. It's pretty silly that it's required at all IMHO, but I know that's the fix for angular material. I think the main angular packages are similar.

flensrocker commented 2 years ago

I only had problems with the migrations of Angular/Material and CDK. The migrations of the main angular packages (core etc.) worked fine.

NicholaAlkhouri commented 2 years ago

@AgentEnder thanks, adding the "tsConfig" to the test target works perfectly.

the-prateek-mishra commented 2 years ago

@AgentEnder @NicholaAlkhouri could you please add a code snippet as to where to add the tsConfig?

NicholaAlkhouri commented 2 years ago

@prateek-giddh

"my-lib": {
 ...
  "architect": {
    "build": {
        "options": {
           "tsConfig": "path/to/your/tsconfig.lib.json",
         }
    },
 ...
},

In case the library is not buildable


"my-lib": {
 ...
  "architect": {
    "test": {
        "options": {
           "tsConfig": "path/to/your/tsconfig.lib.json",
         }
    },
  ...
},
the-prateek-mishra commented 2 years ago

@NicholaAlkhouri thanks for the code snippet. Unfortunately, after adding the "test" configuration to my non-buildable lib, I am getting error Cannot read property 'startsWith' of undefined at Running migration update-angular-config-v13 step.

Complete Logs:

Running migration set-default-base-if-not-set Successfully finished set-default-base-if-not-set

Running migration 13-0-0-config-locations Successfully finished 13-0-0-config-locations

Running migration set-parallel-default Successfully finished set-parallel-default

Running migration 13-3-0-tsc-location Successfully finished 13-3-0-tsc-location

Running migration 13-6-0-remove-old-task-runner-options Successfully finished 13-6-0-remove-old-task-runner-options

Running migration 13-9-0-update-decorate-cli Successfully finished 13-9-0-update-decorate-cli

Running migration 13-9-0-replace-tao-with-nx Successfully finished 13-9-0-replace-tao-with-nx

Running migration add-postcss-packages Successfully finished add-postcss-packages

Running migration update-angular-config Successfully finished update-angular-config

Running migration update-libraries Successfully finished update-libraries

Running migration update-angular-jest-config Successfully finished update-angular-jest-config

Running migration update-testing-imports Successfully finished update-testing-imports

Running migration opt-out-testbed-teardown Successfully finished opt-out-testbed-teardown

Running migration update-mfe-config-to-module-syntax Successfully finished update-mfe-config-to-module-syntax

Running migration remove-library-generator-style-default Successfully finished remove-library-generator-style-default

Running migration fix-incorrect-mfe-setups Successfully finished fix-incorrect-mfe-setups

Running migration add-cypress-mfe-workaround Successfully finished add-cypress-mfe-workaround

Running migration migrate-karma-config Successfully finished migrate-karma-config

Running migration set-build-libs-from-source Successfully finished set-build-libs-from-source

Running migration ngrx-store-migration-13-beta Successfully finished ngrx-store-migration-13-beta

Running migration ngrx-store-migration-13-rc Successfully finished ngrx-store-migration-13-rc

Running migration ngrx-effects-migration-03 Successfully finished ngrx-effects-migration-03

Running migration schematic-options-13 Successfully finished schematic-options-13

Running migration update-angular-config-v13 Cannot read property 'startsWith' of undefined

NicholaAlkhouri commented 2 years ago

@prateek-giddh I can think of two possibilities: 1- one of your projects/libraries doesn't have the architect properties, even if you don't need it just add it as empty object "architect": {}, 2- you didn't specified the builder for your target (the test in your case), for example I use "@nrwl/jest:jest" builder

"test": {
          "builder": "@nrwl/jest:jest",
          "outputs": ["coverage/libs/dir/lib1"],
          "options": {
            "tsConfig": "libs/dir/lib1/tsconfig.lib.json",
            "jestConfig": "libs/dir/lib1/jest.config.js",
            "passWithNoTests": true
          }
        },
the-prateek-mishra commented 2 years ago

Thank you so much @NicholaAlkhouri for such an in-depth explanation. The issue is caused due to the Jest configuration. A few old libraries were missing the Jest builder. Thanks once again!

khyamay commented 2 years ago

Came across this issue today, looking at some of the purposed solution, I think adding the tsConfig seems to fix it. However looking at the examples I think, path for the tsConfig should be path/to/src/tsconfig.spec.ts if it's inside test block, path/to/src/tsconfig.e2e.ts if it's inside e2e block and path/to/src/tsconfig.app.ts if it's inside build block. At least that's what I have observed from the some of auto generated ones inside angular json.

jimbarrett33 commented 2 years ago

For me, this does only occur with angular/material and angular/cdk migrations for me. This is my second recent migration and I have no idea why those migrations care at all about jest tsconfig but...

The problem with the proposed fix for tests is that when running a jest test with tsconfig.json it reports that tsconfig.json in the configuration is deprecated. Eventually, either angular/material migration or jest run time will win out. I'm not even sure where to provide an issue on angular/material migration that anyone would care about and would be fixed.

labeled commented 2 years ago

We are using workspace.json with project.json files in each application / library. I'm having this issue on nearly everything in the monorepo. Here is a snippet of some of the errors image Here's a snip from one of the libraries projects project.json file image If I'm understanding this conversation correctly, I must have a "tsconfig" property set under every one of the options?

flensrocker commented 2 years ago

@labeled Yes

...
"outputs": ...
"options": {
  "tsConfig": "libs/run-manager-unit-bom-page/feature/tsconfig.lib.json",
  "project": "libs/run-manager-unit-bom-page/feature/ng-package.json"
},
...

As a question to those who understand generators in more depth:

Is it possible to extend the lib-generator to do this automatically?

labeled commented 2 years ago

@labeled Yes

...
"outputs": ...
"options": {
  "tsConfig": "libs/run-manager-unit-bom-page/feature/tsconfig.lib.json",
  "project": "libs/run-manager-unit-bom-page/feature/ng-package.json"
},
...

As a question to those who understand generators in more depth:

Is it possible to extend the lib-generator to do this automatically?

@flensrocker Thank you for the answer. You can extend the lib-generators. We create our own that wrap the lib and app generator to include some setup that must be applied to our orgs applications. Create you generator and do something like this

export default async function (host: Tree, schema: any) {
  await libraryGenerator(host, schema);

  // custom code to modify files in host here

  await formatFiles(host);

  return () => {
    installPackagesTask(host)
  }
}
flensrocker commented 2 years ago

@labeled Thanks, I will try some day when I find the time... ๐Ÿ˜Ž

yuchuan1 commented 1 year ago

tsConfig is deprecated. https://kulshekhar.github.io/ts-jest/docs/26.5/getting-started/options/ But when I change to all lower case, the fix does not work.

andydavies-oc commented 1 year ago

I have just carried out a migration from 14.2 to latest on an nx angular project and am observing the following:

I am at a bit of a loss as to how to get confidence that the migrations have fully run as expected. Any guidance would be much appreciated.

danielsharvey commented 1 year ago
  • However when I look at the changes made to the files by the migration, some of the modules that were flagged as skipped have actually been modified

I am at a bit of a loss as to how to get confidence that the migrations have fully run as expected. Any guidance would be much appreciated.

I experience the same - what I think is happening:

  1. I have an Angular app which references code from non-buildable libraries. When the app is upgraded, the changes are made to code included/referenced from the non-buildable libraries.
  2. The non-buildable libraries are reported as skipped when processed by the migration themselves.
kenatwex commented 1 year ago

same here

KerickHowlett commented 1 year ago

Why is this closed? It doesn't seem like the issue was ever resolved, based on these last few posts.

AgentEnder commented 1 year ago

This is coming straight from the Angular and Angular Material migrations. They look specifically for a tsConfig property in either the build or test target for projects before updating them.

I'm not sure why its a requirement, since its 100% not needed for the build or test runs. Regardless, the issue is closed because its got a noted workaround, and isn't something thats actionable on our side of things.

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.