Skip to content

Cannot find @sentry/angular-ivy module in Jest tests when using Angular 17.x #9628

Closed as not planned
@NoNameProvided

Description

@NoNameProvided

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/angular-ivy

SDK Version

7.81.1

Framework Version

17.0.4

Link to Sentry event

No response

SDK Setup

No response

Steps to Reproduce

  1. I have updated our project to the latest Angular 17.x version
  2. I have updated Sentry to the latest version that requires Angular
  3. I have tried to run the tests and I received a module not found error.

We are using @angular-builders/jest to run our tests via Jest (the problem surfaces with default configuration).

Steps to reproduce:

  • generate a new Angular project
  • configure @angular-builders/jest following readme
  • import sentry in the app component
  • create a test that imports the app component
  • run the test and observe that Jest fails with a module not found import error

Expected Result

Jest tests continue to work without a problem.

Actual Result

Every test fails that references a file that imports Sentry in any way with the following message:

Cannot find module '@sentry/angular-ivy' from '<my-app>/path-to-file-where-sentry-is-imported.ts'

I think the root cause of this problem is the same as reported in this issue:

Tests will start to work again when I revert back the referenced change by adding the main entry point in the node_modules folder:

"main": "bundles/sentry-angular-ivy.umd.js",

There is a workaround. The following snippet should be added to the Jest config:

  moduleNameMapper: {
    '@sentry/angular-ivy': '<rootDir>/node_modules/@sentry/angular-ivy/bundles/sentry-angular-ivy.umd.js',
  },

This mandatory workaround should be possibly documented somewhere prominent.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Package: angularIssues related to the Sentry Angular SDK

    Type

    No type

    Projects

    Status

    Waiting for: Product Owner

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions