Back to Nx

Set Isolated Modules

packages/angular/src/migrations/update-22-3-0/set-isolated-modules.md

22.7.11.5 KB
Original Source

Set isolatedModules to true in TypeScript test configurations

Sets the TypeScript isolatedModules compiler option to true in tsconfig.spec.json files for Angular projects using the Jest test runner.

Examples

The migration updates TypeScript test configuration files in Angular projects using the Jest test runner to set the isolatedModules compiler option:

Before
jsonc
// apps/my-app/tsconfig.spec.json
{
  "compilerOptions": {
    "outDir": "./out-tsc/spec",
  },
}
After
jsonc
// apps/my-app/tsconfig.spec.json
{
  "compilerOptions": {
    "outDir": "./out-tsc/spec",
    "isolatedModules": true,
  },
}

If the value is already set to true or inherited from an extended tsconfig file, the migration will not modify the configuration:

Before
jsonc
// tsconfig.json
{
  "compilerOptions": {
    "isolatedModules": true,
  },
}
jsonc
// apps/my-app/tsconfig.spec.json
{
  "extends": "../../tsconfig.json",
  "compilerOptions": {
    "outDir": "./out-tsc/spec",
  },
}
After
jsonc
// tsconfig.json
{
  "compilerOptions": {
    "isolatedModules": true,
  },
}
jsonc
// apps/my-app/tsconfig.spec.json
{
  "extends": "../../tsconfig.json",
  "compilerOptions": {
    "outDir": "./out-tsc/spec",
  },
}

The migration only processes TypeScript test configuration files (tsconfig.spec.json or custom test tsconfig files referenced by @nx/jest:jest tasks) in Angular projects.