build icon indicating copy to clipboard operation
build copied to clipboard

Problems with @sentry/astro on Netlify using SSR

Open whitep4nth3r opened this issue 3 weeks ago • 1 comments

Describe the bug

I am opening this issue to cross-reference this issue from the Sentry organisation: https://github.com/getsentry/sentry-javascript/issues/12603

Steps to reproduce

  1. Create an Astro project that uses SSR
  2. Install Sentry using npx astro add @sentry/astro (see more docs here)
  3. Deploy to Netlify
  4. Navigate to any page that uses SSR
  5. Observe the error logs in Netlify such as:
WARN   Sentry Logger [warn]: Failed to register ESM hook Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/var/task/node_modules/@opentelemetry/instrumentation/hook.mjs' imported from /var/task/node_modules/@sentry/node/esm/sdk/initOtel.js
    at finalizeResolution (node:internal/modules/esm/resolve:269:11)
    at moduleResolve (node:internal/modules/esm/resolve:937:10)
    at moduleResolveWithNodePath (node:internal/modules/esm/resolve:1161:14)
    at defaultResolve (node:internal/modules/esm/resolve:1204:79)
    at nextResolve (node:internal/modules/esm/hooks:866:28)
    at Hooks.resolve (node:internal/modules/esm/hooks:304:30)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:345:35)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:227:38)
    at ModuleLoader.import (node:internal/modules/esm/loader:315:34)
    at Hooks.register (node:internal/modules/esm/hooks:165:53) {
  code: 'ERR_MODULE_NOT_FOUND',
  url: 'file:///var/task/node_modules/@opentelemetry/instrumentation/hook.mjs'
}

Configuration

My current netlify.toml looks like this, the included_files is attempting to fix the issue. Please see the referenced issue in the description above for more details.

[build]
  command = "npm run build"
  functions = "netlify/functions"
  publish = "dist"

[functions]
  included_files = ["node_modules/@opentelemetry/instrumentation/hook.mjs", "node_modules/import-in-the-middle/hook.mjs"]

Deploy logs

No deploys are failing.

whitep4nth3r avatar Jun 25 '24 12:06 whitep4nth3r