sentry-javascript icon indicating copy to clipboard operation
sentry-javascript copied to clipboard

Nuxt: Cannot find module: node_modules\@opentelemetry\resources\build\esm\detectors\platform\node\machine-id\execAsync

Open simonmaass opened this issue 1 year ago • 42 comments

Is there an existing issue for this?

  • [x] I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
  • [x] I have reviewed the documentation https://docs.sentry.io/
  • [x] I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/nuxt

SDK Version

8.51.0

Framework Version

Nuxt 3.15.3

Link to Sentry event

No response

Reproduction Example/SDK Setup

No response

Steps to Reproduce

  1. install @sentry/nuxt
  2. add '@sentry/nuxt/module' to modules in nuxt config
  3. run yarn dev

Expected Result

works

Actual Result

[nuxt] [request error] [unhandled] [500] Cannot find module 'node_modules@opentelemetry\resources\build\esm\detectors\platform\node\machine-id\execAsync' imported from node_modules@opentelemetry\resources\build\esm\detectors\platform\node\machine-id\getMachineId-win.js

simonmaass avatar Jan 28 '25 10:01 simonmaass

i started having the same problem

adamkasper avatar Jan 28 '25 11:01 adamkasper

Hey, can you show your actual setup code here? That would help us to reproduce what is going on. So, in which files have you put what Sentry config?

mydea avatar Jan 28 '25 16:01 mydea

this might be related and due to nuxt: https://github.com/nuxt/nuxt/issues/30749#issuecomment-2618278860

when reverting to nuxt 3.15.2 everything works again.

simonmaass avatar Jan 28 '25 18:01 simonmaass

i also got it after upgrading from 3.15.2 to 3.15.3, so that's it

edit: i've just tried the new 3.15.4 and it's still happening

adamkasper avatar Jan 29 '25 09:01 adamkasper

Hi, thanks for reporting, we'll take a look.

andreiborza avatar Jan 29 '25 13:01 andreiborza

I tried to reproduce this with a fresh nuxt project set up via nuxi and set up sentry using npx @sentry/wizard@latest -i nuxt and did not run into this issue, neither with build nor with dev.

Could you provide a reproduction repo please?

andreiborza avatar Jan 30 '25 21:01 andreiborza

I have same issue

Tried to reproduce in clean project, you can achieve same result with pnpm and NOT linux

Node 22.14.0 pnpm 10.3.0 macos (arm64)

pnpx nuxi@latest init test-project
cd test-project
pnpx @sentry/wizard@latest -i nuxt
pnpm dev

Then open localhost:3000 in browser

Image

Moonrag avatar Feb 12 '25 09:02 Moonrag

@Moonrag thanks, we'll take a look. Just one thing to note, we currently do not support running Sentry in nuxt's dev mode.

You could conditionally enable it if you want:

// nuxt.config.ts
sentry: {
  enabled: !import.meta.dev,
},

andreiborza avatar Feb 12 '25 12:02 andreiborza

@andreiborza

// nuxt.config.ts sentry: { enabled: !import.meta.dev, },

thanks, but unfortunately, this is not working :(

we don't actually need sentry in dev mode, but problem exists if module installed and added to nuxt.config.ts, as topic starter already mentioned in his reproduction steps. in real project we disable sentry in client/server configs with runtime config

Moonrag avatar Feb 12 '25 12:02 Moonrag

It may not work as the option enabled was added in version 9 of the SDK. If you want you can upgrade (in most cases, you can just update without changing code): https://docs.sentry.io/platforms/javascript/guides/nuxt/migration/v8-to-v9/

s1gr1d avatar Feb 12 '25 12:02 s1gr1d

Upgrading to v9 doesn't fix this bug, but the enabled option is available -- import.meta.dev is undefined for me though, but I could disable sentry during development using:

{
  sentry: {
    enabled: process.env.NODE_ENV === 'production',
  }
}

thijsw avatar Feb 24 '25 10:02 thijsw

@s1gr1d do we have an action item here? Superficially to me this issue seems resolved with enabled, but if nuxt is still not working with dev mode we should track it somewhere else. Do we already have an issue for nuxt dev mode?

lforst avatar Feb 24 '25 11:02 lforst

The issue with execAsync specifically is not resolved yet and I think we cannot to much from our side here. Me and @Lms24 created a reproduction with some explanations in the readme here.

The dev mode works when the import has a file extension: import { execAsync } from './execAsync'; in getMachineId-darwin.js to import { execAsync } from './execAsync.js'; (adding the file extension). It's because ESM requires the .js file extensions to work and there is a tracking issue in OTel to support the ESM spec (which also means adding the file extensions): https://github.com/open-telemetry/opentelemetry-js/issues/4898

However, as pointed out in the reproduction linked at the beginning of my comment, it works with a Nightly version of Nuxt 4. So it's maybe not only an OTel/ESM support issue. The PR related to the specific Nuxt nightly release is this one: https://github.com/nuxt/nuxt/pull/30922

This fix will also be shipped in Nuxt 3.16.0, so this might also fix this issue (but there is no nightly, so I was not able to test it).

s1gr1d avatar Feb 24 '25 13:02 s1gr1d

Closing this as this was fixed by Nuxt in v3.16.0 (see comment above for more information).

s1gr1d avatar Mar 10 '25 11:03 s1gr1d

I am getting this issue but for ssr routes

nuxt 3.16.0 sentry/nuxt 9.5.0

josephjoeljo avatar Mar 12 '25 23:03 josephjoeljo

I found out this error triggered in our project by using defineNuxtModule somewhere in code.

Add rollup config to nuxt.config.ts fixed:

vite: {
    build: {
    rollupOptions: {
      output: {
        manualChunks(id) {
          if (id.includes('node_modules')) {
            return 'vendor'
          }
        },
      },
    },
},

nam-nguyenhai avatar May 13 '25 14:05 nam-nguyenhai

@s1gr1d Could you evaluate if this ticket should be reopened? We're experiencing the same issue again with Nuxt 3.17 and @sentry/nuxt 9.21.0

PatrickBauer avatar May 20 '25 13:05 PatrickBauer

Thanks for notifying!

Reopening as this seems to be an issue again. I will take a look at my own reproduction from last time I linked above.


I just tried it with the reproduction and installed the versions you mentioned. However, I was not able to reproduce it. Can you share more details about your project or provide a reproduction? You can base it on the one I already provided.

But in general, it would be useful to know:

  • Package Manager
  • Node version
  • Nitro compatibility date
  • Nuxt compatibility version

s1gr1d avatar May 20 '25 14:05 s1gr1d

Hello,

I get this issue too after upgrading from Nuxt 3.16.2 to 3.17.3. I was not having the trouble with 3.16.2. Sentry was at version 9.12.0, same trouble after upgrade to 9.21.0 Package manager : npm 10.9.2 Node 22.15.1 compatibilityDate in nuxt.config.ts : 2024-09-04 Nuxt compatibilityVersion: 4 (was already this one before upgrade to 3.17.3)

(I was not having the trouble either with Node 20 and Nuxt 3.16.2.)

ℹ Error: Cannot find module '.\node_modules\@sentry\node\node_modules\@opentelemetry\resources\build\esm\detectors\platform\node\machine-id\execAsync' imported from .\node_modules\@sentry\node\node_modules\@opentelemetry\resources\build\esm\detectors\platform\node\machine-id\getMachineId-win.js

 ⁃ at finalizeResolution (node:internal/modules/esm/resolve:275:11)
 ⁃ at moduleResolve (node:internal/modules/esm/resolve:860:10)
 ⁃ at defaultResolve (node:internal/modules/esm/resolve:984:11)
 ⁃ at nextResolve (node:internal/modules/esm/hooks:748:28)
 ⁃ at resolve (D:/redacted/node_modules/import-in-the-middle/hook.js:334:26)

   329 ┃      const { parentURL = '' } = context
   330 ┃      const newSpecifier = deleteIitm(specifier)
   331 ┃      if (isWin && parentURL.indexOf('file:node') === 0) {
   332 ┃        context.parentURL = ''
   333 ┃      }
 ❯ 334 ┃      const result = await parentResolve(newSpecifier, context, parentResolve)
   335 ┃      if (parentURL === '' && !EXTENSION_RE.test(result.url)) {
   336 ┃        entrypoint = result.url
   337 ┃        return { url: result.url, format: 'commonjs' }
   338 ┃      }
   339 ┃

 ⁃ at nextResolve (node:internal/modules/esm/hooks:748:28)
 ⁃ at Hooks.resolve (node:internal/modules/esm/hooks:240:30)
 ⁃ at MessagePort.handleMessage (node:internal/modules/esm/worker:199:24)
 ⁃ at [nodejs.internal.kHybridDispatch] (node:internal/event_target:827:20)
 ⁃ at MessagePort.<anonymous> (node:internal/per_context/messageport:23:28)

[CAUSE]
Error {
  name: 'Error',
  message: "Cannot find module
  'D:\\redacted\\node_modules\\@sentry\\node\\node_modules\\@opentelemetry\\resources\\build\\esm\\detectors\\platform\\node\\machine-id\\execAsync'
  imported from
  D:\\redacted\\node_modules\\@sentry\\node\\node_modules\\@opentelemetry\\resources\\build\\esm\\detectors\\platform\\node\\machine-id\\getMachineId-win.js",
  stack: "Cannot find module 'D:\\redacted\\node_modules\\@sentry\\node\\node_modules\\@opentelemetry\\resources\\build\\esm\\detectors\\platform\\node\\machine-id\\execAsync' imported from D:\\redacted\\node_modules\\@sentry\\node\\node_modules\\@opentelemetry\\resources\\build\\esm\\detectors\\platform\\node\\machine-id\\getMachineId-win.js\n" +
  '    at finalizeResolution (node:internal/modules/esm/resolve:275:11)\n' +
  '    at moduleResolve (node:internal/modules/esm/resolve:860:10)\n' +
  '    at defaultResolve (node:internal/modules/esm/resolve:984:11)\n' +
  '    at nextResolve (node:internal/modules/esm/hooks:748:28)\n' +
  'at resolve (D:/redacted/node_modules/import-in-the-middle/hook.js:334:26)\n' +
  '    at nextResolve (node:internal/modules/esm/hooks:748:28)\n' +
  '    at Hooks.resolve (node:internal/modules/esm/hooks:240:30)\n' +
  '    at MessagePort.handleMessage (node:internal/modules/esm/worker:199:24)\n' +
  '    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:827:20)\n' +
  '    at MessagePort.<anonymous> (node:internal/per_context/messageport:23:28)',
  code: 'ERR_MODULE_NOT_FOUND',
  url: 'file:///D:/redacted/node_modules/@sentry/node/node_modules/@opentelemetry/resources/build/esm/detectors/platform/node/machine-id/execAsync',
  [Symbol(Symbol.toStringTag)]: 'Error',
}

fredericDelaporte avatar May 20 '25 16:05 fredericDelaporte

Thank you for the stack trace! 💯 Would you be able to share a reproduction? I would need this reproduction in order to debug this and find out what's going on here.

I am still able to reproduce this issue with the reproduction me and @Lms24 created. But as soon I am upgrading the versions here, the issue is no longer reproducible. I also tried different new versions and package managers.

s1gr1d avatar May 21 '25 08:05 s1gr1d

A quick work-around (for now) for those who got into this issue - use @sentry/core module instead, if the utility you need exists in that module.

cadenzah avatar May 21 '25 08:05 cadenzah

@cadenzah can you share which utility created an issue for you?

s1gr1d avatar May 21 '25 12:05 s1gr1d

@s1gr1d I was using @sentry/nuxt, and I previously used Sentry.init() only and it worked fine. But I added Sentry.getGlobalScope().setTag() and the issue occured. I imported the identical method from @sentry/core and used it, and it worked.

FYI used Nuxt v3.17.3, Node v22.14.0, @sentry/nuxt 9.22.0, and it worked okay if I used it with Node v22 (others being same)

cadenzah avatar May 21 '25 15:05 cadenzah

As I am not able to get a working reproduction to be able look into this, I think it's fine to use this workaround. Most function from the @sentry/nuxt SDK are a re-export of @sentry/core, so it's fine to import them from there.

s1gr1d avatar May 22 '25 12:05 s1gr1d

The problem is that the package @opentelemetry/api distributes invalid esm code, esm code imports need to use the .js extension but instead it tries to import without any extension, which is invalid esm code and Node.js cannot run it.

https://github.com/open-telemetry/opentelemetry-js/issues/3989

remorses avatar May 23 '25 07:05 remorses

Yes, we are aware that this is because of the missing .js (mentioned in this comment above). However, Nuxt should be able to handle this and this should have been fixed already (I cannot reproduce the error).

s1gr1d avatar May 23 '25 07:05 s1gr1d

It's still an issue. I don`t understand the specific case yet, as the issue is flaky. But from time to time, it's randomly happening on the dev environment.

Nuxt: 3.17.4 Sentry: 9.22.0

Perdolique avatar May 23 '25 12:05 Perdolique

I do neither have a repro for now. The failing project I have is not public and heavy.

fredericDelaporte avatar May 23 '25 18:05 fredericDelaporte

As I cannot reproduce it I can only guess here. It could be, that code that should not be bundled in, is bundled in the build output. Does adding this to nuxt.config.ts solve the problem?

  nitro: {
    rollupConfig: {
       external: ['@sentry/nuxt']
    }
  },

s1gr1d avatar May 28 '25 09:05 s1gr1d

I adjusted the rollup config but that didn't solve the problem for me.

dredav avatar May 28 '25 12:05 dredav