Skip to content

Sentry Instrumentation breaks Next on VercelΒ #16089

@giladrom

Description

@giladrom

Environment

SaaS (https://sentry.io/)

Steps to Reproduce

Installed the latest Sentry plugin, followed the instructions, enabled instrumentation and deployed to Vercel.
Next 15.3, sentry/nextjs 9.12.0

Expected Result

Next project should load as expected and send errors to Sentry.

Actual Result

Node.js exits with an error code, Page returns a 500 error, and Vercel logs show the following:

Error: An error occurred while loading the instrumentation hook
    at <unknown> (___next_launcher.cjs:62:16)
    at withNextRequestContext (___next_launcher.cjs:30:18)
    at Server.<anonymous> (___next_launcher.cjs:58:11)
    at <unknown> (../../opt/rust/nodejs.js:16:5779) {
  [cause]: Error: require() of ES Module /var/task/.next/server/instrumentation.js from /var/task/node_modules/next/dist/server/next-server.js not supported.
  instrumentation.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
  Instead either rename instrumentation.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in /var/task/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).
  
      at <unknown> (../../opt/rust/nodejs.js:2:12169)
      at Function.fr (../../opt/rust/nodejs.js:2:12547)
      at Ee.e.<computed>.we._load (../../opt/rust/nodejs.js:2:12139) {
    code: 'ERR_REQUIRE_ESM'
  }
}

Product Area

Unknown

Link

No response

DSN

No response

Version

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions