Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All tests failing with Package subpath './src/ngtsc/reflection' is not defined by "exports" in node_modules/@angular/compiler-cli/package.json #8442

Closed
ravivit9 opened this issue Jan 8, 2022 · 3 comments
Labels
outdated scope: angular Issues related to Angular support in Nx type: bug

Comments

@ravivit9
Copy link

ravivit9 commented Jan 8, 2022

After nx migrating latest, started experiencing below unit test failures for all projects, libraries in mono repo.

Configurations

nx.json

{
  "npmScope": "jopoworkspace",
  "affected": {
    "defaultBase": "master"
  },
  "implicitDependencies": {
    "angular.json": "*",
    "package.json": {
      "dependencies": "*",
      "devDependencies": "*"
    },
    "tsconfig.base.json": "*",
    "tslint.json": "*",
    "nx.json": "*",
    ".eslintrc.json": "*"
  },
  "tasksRunnerOptions": {
    "default": {
      "runner": "@nrwl/nx-cloud",
      "options": {
        "accessToken": "sometoken=",
        "cacheableOperations": ["build", "lint", "test", "e2e"],
        "canTrackAnalytics": false,
        "showUsageWarnings": true,
        "parallel": 3
      }
    }
  },
  "targetDependencies": {
    "build": [
      {
        "target": "build",
        "projects": "dependencies"
      }
    ]
  },
  "cli": {
    "defaultCollection": "@nrwl/angular",
    "analytics": false
  },
  "generators": {
    "@nrwl/angular:application": {
      "style": "scss",
      "linter": "eslint",
      "unitTestRunner": "jest",
      "e2eTestRunner": "cypress"
    },
    "@nrwl/angular:library": {
      "style": "scss",
      "linter": "eslint",
      "unitTestRunner": "jest"
    },
    "@nrwl/angular:component": {
      "style": "scss"
    }
  },
  "defaultProject": "passenger"
}
`
### workspace.json
`{
  "version": 2,
  "projects": {
    "api-interfaces": {
      "tags": []
    },
    "apis-application": {
      "tags": []
    },
  }
}
```
`


### package.json
`  ```
"dependencies": {
    "@agm/core": "^3.0.0-beta.0",
    "@agm/markerclusterer": "^3.0.0-beta.0",
    "@angular/animations": "13.1.1",
    "@angular/cdk": "13.1.1",
    "@angular/common": "13.1.1",
    "@angular/compiler": "13.1.1",
    "@angular/core": "13.1.1",
    "@angular/forms": "13.1.1",
    "@angular/platform-browser": "13.1.1",
    "@angular/platform-browser-dynamic": "13.1.1",
    "@angular/router": "13.1.1",
    "@fortawesome/fontawesome-free": "^5.15.3",
    "@google/markerclustererplus": "^5.1.3",
    "@nestjs/common": "^8.0.0",
    "@nestjs/core": "^8.0.0",
    "@nestjs/jwt": "^7.2.0",
    "@nestjs/mongoose": "^7.2.4",
    "@nestjs/platform-express": "^8.0.0",
    "@ng-bootstrap/ng-bootstrap": "^9.1.0",
    "@ngx-pwa/local-storage": "^11.1.0",
    "@nrwl/angular": "13.4.3",
    "@types/bluebird": "^3.5.34",
    "@types/chart.js": "^2.9.31",
    "@types/jsonwebtoken": "^8.5.1",
    "@types/sequelize": "^4.28.10",
    "@types/validator": "^13.1.3",
    "agm-direction": "^0.8.9",
    "agm-overlays": "^2.0.0",
    "angular-bootstrap-md": "^11.1.0",
    "animate.css": "^4.1.1",
    "aws-sdk": "^2.905.0",
    "aws-sns-sms": "^1.0.2",
    "axios": "^0.24.0",
    "bcrypt": "^5.0.1",
    "bootstrap": "^5.0.0",
    "canvas": "^2.8.0",
    "chart.js": "^2.9.4",
    "crypto": "^1.0.1",
    "crypto-js": "^4.0.0",
    "esm": "^3.2.25",
    "hammerjs": "^2.0.8",
    "igniteui-angular": "^11.1.10",
    "jsonwebtoken": "^8.5.1",
    "jwt-decode": "^3.1.2",
    "libphonenumber-js": "^1.9.17",
    "mon": "0.0.8",
    "mongoose": "^5.12.8",
    "mysql2": "^2.3.3",
    "ng-pick-datetime": "^7.0.0",
    "ng2-charts": "^2.4.2",
    "ngx-auto-unsubscribe": "^3.0.1",
    "ngx-charts": "^3.0.2",
    "ngx-connection-service": "^7.0.3",
    "ngx-doc-viewer": "^2.0.2",
    "ngx-light-carousel": "^1.1.10",
    "ngx-material-timepicker": "^5.5.3",
    "ngx-snackbar": "^2.0.1",
    "ngx-swiper-wrapper": "^10.0.0",
    "node-gyp": "^8.0.0",
    "nodemailer": "^6.6.0",
    "otp-generator": "^2.0.0",
    "reflect-metadata": "^0.1.13",
    "rxjs": "^7.4.0",
    "sequelize": "^6.12.2",
    "sequelize-cli": "^6.3.0",
    "sequelize-typescript": "^2.1.1",
    "source-map-support": "^0.5.21",
    "stream": "0.0.2",
    "swiper": "^6.6.1",
    "tslib": "^2.2.0",
    "zone.js": "0.11.4"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "13.1.2",
    "@angular-eslint/eslint-plugin": "13.0.1",
    "@angular-eslint/eslint-plugin-template": "13.0.1",
    "@angular-eslint/template-parser": "13.0.1",
    "@angular/cli": "13.1.2",
    "@angular/compiler-cli": "13.1.1",
    "@angular/language-service": "13.1.1",
    "@angularclass/hmr": "^3.0.0",
    "@compodoc/compodoc": "^1.1.14",
    "@nestjs/schematics": "^8.0.0",
    "@nestjs/testing": "^8.0.0",
    "@nrwl/cli": "13.4.3",
    "@nrwl/cypress": "13.4.3",
    "@nrwl/eslint-plugin-nx": "13.4.3",
    "@nrwl/jest": "13.4.3",
    "@nrwl/linter": "13.4.3",
    "@nrwl/nest": "13.4.3",
    "@nrwl/node": "13.4.3",
    "@nrwl/nx-cloud": "13.0.2",
    "@nrwl/tao": "13.4.3",
    "@nrwl/workspace": "13.4.3",
    "@types/crypto-js": "^4.0.1",
    "@types/cryptr": "^4.0.1",
    "@types/googlemaps": "^3.43.3",
    "@types/jest": "27.0.2",
    "@types/mongoose": "^5.10.5",
    "@types/node": "15.0.2",
    "@types/swiper": "^5.4.2",
    "@typescript-eslint/eslint-plugin": "5.3.1",
    "@typescript-eslint/parser": "5.3.1",
    "babel-eslint": "^10.1.0",
    "babel-preset-env": "^1.7.0",
    "codelyzer": "6.0.2",
    "cypress": "^7.3.0",
    "dotenv": "10.0.0",
    "eslint": "8.2.0",
    "eslint-config-prettier": "8.3.0",
    "eslint-plugin-cypress": "^2.10.3",
    "husky": "^6.0.0",
    "install-peers": "^1.0.3",
    "jest": "27.0.3",
    "jest-preset-angular": "9.0.3",
    "parcel-bundler": "^1.9.4",
    "prettier": "2.3.2",
    "pretty-quick": "^3.1.0",
    "sass": "^1.45.1",
    "sass-lint": "^1.13.1",
    "scss-lint": "0.0.0",
    "ts-jest": "27.0.5",
    "ts-node": "9.1.1",
    "tslint": "6.1.3",
    "tslint-config-prettier": "^1.18.0",
    "typescript": "4.4.4"
  },

jest.config.js

const { getJestProjects } = require('@nrwl/jest');

module.exports = {
  extensionsToTreatAsEsm: ['.ts'],
  // preset: 'ts-jest/presets/default-esm', // or other ESM presets
  preset: 'jest-preset-angular',
  globals: {
    'ts-jest': {
      useESM: true,
    },
  },
  moduleNameMapper: {
    '^(\\.{1,2}/.*)\\.js$': '$1',
  },
  moduleFileExtensions: [
    ...defaults.moduleFileExtensions,
    'ts',
    'html',
    'js',
    'json',
    'mjs',
  ],
  resolver: 'jest-preset-angular/build/resolvers/ng-jest-resolver.js',
  transformIgnorePatterns: [
    '<rootDir>/node_modules/(?!.*\\.mjs$)',
    '<rootDir>/node_modules/(?!ngx-snackbar|igniteui-angular/).+\\.js$',
  ],
  transform: {
    '^.+\\.(ts|js|mjs|html|svg)$': 'jest-preset-angular',
  },

  projects: [
    ...getJestProjects(),
    '<rootDir>',
    '<rootDir>/libs/api-interfaces',
    '<rootDir>/libs/apis/application',`
  ],
};
```

### jest.preset.js
`const nxPreset = require('@nrwl/jest/preset');
const jestPresetAngularSerializers = require('jest-preset-angular/build/serializers');

module.exports = {
  ...nxPreset,
  verbose: true,
  testMatch: ['**/+(*.)+(spec|test).+(ts|js)?(x)'],
  transform: {
    '^.+\\.(ts|js|html)$': 'ts-jest',
    '^.+\\.js$': 'babel-jest',
    '^.+.(ts|mjs|js|html)$': 'jest-preset-angular',
  },
  resolver: '@nrwl/jest/plugins/resolver',
  moduleFileExtensions: ['ts', 'js', 'html'],
  coverageReporters: ['html'],
  moduleNameMapper: {
    '^lodash-es$': 'lodash',
  },
  transformIgnorePatterns: [
    '<rootDir>/node_modules/(?!(jest-test))',
    '<rootDir>/node_modules/(?!lodash-es)',
    '<rootDir>/node_modules/(?!.*.mjs$)',
    '<rootDir>/node_modules/(?!ngx-snackbar)',
    '<rootDir>/node_modules/(?!igniteui-angular)',
  ],
  snapshotSerializers: jestPresetAngularSerializers,
};
`

## Current Behavior
`npx nx run-many --force-exit --detectOpenHandles  --target=test --all `
```
> nx run apis-feature-user-locations:test --forceExit --detectOpenHandles 
**Package subpath './src/ngtsc/reflection' is not defined by "exports" in /Users/ravindra/projects/gitlab/jopoworkspace/node_modules/@angular/compiler-cli/package.json**
```

<!-- What is the behavior that currently you experience? -->
All tests are failing straight away with the above error.

## Expected Behavior
All tests must pass or fail with a reason respective to unit test of component, library.

## Steps to Reproduce
`nx migrate latest`
`nx migrate --run-migrations=migrations.json`

<!-- Can you reproduce this on https://github.com/nrwl/nx-examples? -->
<!-- If so, open a PR with your changes and link it below. -->
<!-- If not, please provide a minimal Github repo -->
<!-- At the very least, provide as much detail as possible to help us reproduce the issue -->

### Failure Logs
Package subpath './src/ngtsc/reflection' is not defined by "exports" in /Users/ravindra/projects/gitlab/jopoworkspace/node_modules/@angular/compiler-cli/package.json

### Environment
% nx report

>  NX  Report complete - copy this into the issue template

  Node : 16.10.0
  OS   : darwin x64
  npm  : 7.24.0
  
  nx : 13.4.3
  @nrwl/angular : 13.4.3
  @nrwl/cli : 13.4.3
  @nrwl/cypress : 13.4.3
  @nrwl/devkit : 13.4.3
  @nrwl/eslint-plugin-nx : 13.4.3
  @nrwl/express : undefined
  @nrwl/jest : 13.4.3
  @nrwl/linter : 13.4.3
  @nrwl/nest : 13.4.3
  @nrwl/next : undefined
  @nrwl/node : 13.4.3
  @nrwl/nx-cloud : 13.0.2
  @nrwl/react : undefined
  @nrwl/react-native : undefined
  @nrwl/schematics : undefined
  @nrwl/tao : 13.4.3
  @nrwl/web : undefined
  @nrwl/workspace : 13.4.3
  @nrwl/storybook : 13.4.3
  @nrwl/gatsby : undefined
  typescript : 4.4.4
  rxjs : 7.5.1
  ---------------------------------------
  Community plugins:
         @angular/animations: 13.1.1
         @angular/cdk: 13.1.1
         @angular/common: 13.1.1
         @angular/compiler: 13.1.1
         @angular/core: 13.1.1
         @angular/forms: 13.1.1
         @angular/platform-browser: 13.1.1
         @angular/platform-browser-dynamic: 13.1.1
         @angular/router: 13.1.1
         @ng-bootstrap/ng-bootstrap: 9.1.3
         @ngx-pwa/local-storage: 11.1.0
         angular-bootstrap-md: 11.1.0
         igniteui-angular: 11.1.37
         @angular-devkit/build-angular: 13.1.2
         @angular/cli: 13.1.2
         @angular/compiler-cli: 13.1.1
         @angular/language-service: 13.1.1

workspace %(node:37048) [DEP0148] DeprecationWarning: Use of deprecated folder mapping "./" in the "exports" field module resolution of the package at /Users/username/projects/gitlab/workspace/node_modules/tslib/package.json.
Update this package.json to use a subpath pattern like "./*".
(Use `node --trace-deprecation ...` to show where the warning was created)
workspace % 

@ravivit9
Copy link
Author

ravivit9 commented Jan 8, 2022

I am really stuck with this issue and unable to commit my code without test suites running. The mono repo contains around 100+ library modules and 8 apps consuming these libraries. Greatly appreciate your help on resolving this please.

@FrozenPandaz FrozenPandaz added the scope: angular Issues related to Angular support in Nx label Jan 15, 2022
@Coly010
Copy link
Contributor

Coly010 commented Jan 18, 2022

Duplicate of #7844

Can you take a look at the workaround listed here: #7844 (comment)

Your jest config looks incorrect and manually edited to match jest-preset-angular's suggestions, which isn't correct for Nx Workspaces.

The comments in the issue above should be able to resolve your issue.
If not, reply to that issue above so that we can keep related items together :)

@Coly010 Coly010 closed this as completed Jan 18, 2022
@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: angular Issues related to Angular support in Nx type: bug
Projects
None yet
Development

No branches or pull requests

3 participants