Skip to content

Unable to resolve path to module '@sentry/nestjs' #14789

Closed
@abriginets

Description

@abriginets

Is there an existing issue for this?

How do you use Sentry?

Self-hosted/on-premise

Which SDK are you using?

@sentry/nestjs

SDK Version

8.47.0

Framework Version

NestJS 10.3.7

Link to Sentry event

No response

Reproduction Example/SDK Setup

import * as Sentry from '@sentry/nestjs';
import dotenv from 'dotenv';

dotenv.config();

if (!process.env.SENTRY_DSN) {
  throw new Error('process.env.SENTRY_DSN is not defined');
}

if (!process.env.SENTRY_ENV) {
  throw new Error('process.env.SENTRY_ENV is not defined');
}

Sentry.init({
  dsn: process.env.SENTRY_DSN,
  sampleRate: 0.1,
  environment: process.env.SENTRY_ENV,
});

Steps to Reproduce

  1. Install @sentry/nestjs package
  2. Add eslint and eslint-import-plugin to your project (you may also just clone https://github.com/abriginets/nest-starter)
  3. Try importing something from @sentry/nestjs. You'll get eslint error

Unable to resolve path to module '@sentry/nestjs'. (eslint import/no-unresolved)

This occurs because of the bad path in package.json of @sentry/nestjs:

  "main": "build/cjs/nestjs/index.js",
  "module": "build/esm/nestjs/index.js",

If you look into filesystem, there won't be nestjs dir.

Image

I've been able to successfully patch this by creating nestjs directory under node_modules/@sentry/nestjs/build/cjs/ and by putting all the files from aforementioned directory into it.

Image

The error was gone after this.

Expected Result

Files location should correspond to what's declared in package.json

Actual Result

Files location and package.json declaration mismatch

Metadata

Metadata

Assignees

Labels

Package: nestjsIssues related to the Sentry Nestjs SDK

Type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions