nextjs - 💡(How to fix) Fix A Node.js module is loaded error in instrumentation.ts [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#85938Fetched 2026-04-08 02:13:21
View on GitHub
Comments
1
Participants
2
Timeline
6
Reactions
0
Author
Timeline (top)
labeled ×2closed ×1commented ×1issue_type_added ×1

Error Message

console:dev: Ecmascript file had an error console:dev: Ecmascript file had an error

Code Example

import { registerOTel } from "@vercel/otel";

export function register() {
  registerOTel("myapp");

  // HINT: // https://github.com/vercel/next.js/issues/51404
  // Make sure commands gracefully respect termination signals (e.g. from Docker)
  // Allow the graceful termination to be manually configurable
  if (
    process.env.NEXT_RUNTIME === "nodejs" &&
    process.env.NEXT_MANUAL_SIG_HANDLE === "true"
  ) {
    process.on("SIGTERM", async () => {
      console.info("Received SIGTERM: ", "starting graceful shutdown");
      // TODO: gracefully shutdown any resources
      await shutdown();
    });
    process.on("SIGINT", async () => {
      console.info("Received SIGINT: ", "starting graceful shutdown");
      await shutdown();
    });
  }
}

async function shutdown() {
  const fs = await import("node:fs");
  fs.writeFileSync("/tmp/shutdown", "1");

  setTimeout(() => {
    process.exit(0);
  }, 20 * 1000); // 20 secs shutdown timeout
}

---

console:dev: (node:9997) Warning: `--localstorage-file` was provided without a valid path
console:dev: (Use `node --trace-warnings ...` to show where the warning was created)
console:dev:./apps/console/src/instrumentation.ts:30:5
console:dev: Ecmascript file had an error
console:dev:   28 |
console:dev:   29 |   setTimeout(() => {
console:dev: > 30 |     process.exit(0);
console:dev:      |     ^^^^^^^^^^^^
console:dev:   31 |   }, 20 * 1000); // 20 secs shutdown timeout
console:dev:   32 | }
console:dev:   33 |
console:dev: 
console:dev: A Node.js API is used (process.exit at line: 30) which is not supported in the Edge Runtime.
console:dev: Learn more: https://nextjs.org/docs/api-reference/edge-runtime
console:dev: 
console:dev: 
console:dev:./apps/console/src/instrumentation.ts:26:20
console:dev: Ecmascript file had an error
console:dev:   24 |
console:dev:   25 | async function shutdown() {
console:dev: > 26 |   const fs = await import("node:fs");
console:dev:      |                    ^^^^^^^^^^^^^^^^^
console:dev:   27 |   fs.writeFileSync("/tmp/shutdown", "1");
console:dev:   28 |
console:dev:   29 |   setTimeout(() => {
console:dev: 
console:dev: A Node.js module is loaded ('node:fs' at line 26) which is not supported in the Edge Runtime.
console:dev: Learn More: https://nextjs.org/docs/messages/node-module-in-edge-runtime

---

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.0.0: Wed Sep 17 21:41:45 PDT 2025; root:xnu-12377.1.9~141/RELEASE_ARM64_T6000
  Available memory (MB): 65536
  Available CPU cores: 10
Binaries:
  Node: 25.1.0
  npm: 11.6.2
  Yarn: N/A
  pnpm: 10.20.0
Relevant Packages:
  next: 16.0.1
  eslint-config-next: N/A
  react: 19.2.0
  react-dom: 19.2.0
  typescript: 5.9.3
Next.js Config:
  output: standalone
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/vercel/next.js

To Reproduce

add above code to instrumentation.ts

Current vs. Expected behavior

src/instrumentation.ts

import { registerOTel } from "@vercel/otel";

export function register() {
  registerOTel("myapp");

  // HINT: // https://github.com/vercel/next.js/issues/51404
  // Make sure commands gracefully respect termination signals (e.g. from Docker)
  // Allow the graceful termination to be manually configurable
  if (
    process.env.NEXT_RUNTIME === "nodejs" &&
    process.env.NEXT_MANUAL_SIG_HANDLE === "true"
  ) {
    process.on("SIGTERM", async () => {
      console.info("Received SIGTERM: ", "starting graceful shutdown");
      // TODO: gracefully shutdown any resources
      await shutdown();
    });
    process.on("SIGINT", async () => {
      console.info("Received SIGINT: ", "starting graceful shutdown");
      await shutdown();
    });
  }
}

async function shutdown() {
  const fs = await import("node:fs");
  fs.writeFileSync("/tmp/shutdown", "1");

  setTimeout(() => {
    process.exit(0);
  }, 20 * 1000); // 20 secs shutdown timeout
}
console:dev: (node:9997) Warning: `--localstorage-file` was provided without a valid path
console:dev: (Use `node --trace-warnings ...` to show where the warning was created)
console:dev:./apps/console/src/instrumentation.ts:30:5
console:dev: Ecmascript file had an error
console:dev:   28 |
console:dev:   29 |   setTimeout(() => {
console:dev: > 30 |     process.exit(0);
console:dev:      |     ^^^^^^^^^^^^
console:dev:   31 |   }, 20 * 1000); // 20 secs shutdown timeout
console:dev:   32 | }
console:dev:   33 |
console:dev: 
console:dev: A Node.js API is used (process.exit at line: 30) which is not supported in the Edge Runtime.
console:dev: Learn more: https://nextjs.org/docs/api-reference/edge-runtime
console:dev: 
console:dev: 
console:dev:./apps/console/src/instrumentation.ts:26:20
console:dev: Ecmascript file had an error
console:dev:   24 |
console:dev:   25 | async function shutdown() {
console:dev: > 26 |   const fs = await import("node:fs");
console:dev:      |                    ^^^^^^^^^^^^^^^^^
console:dev:   27 |   fs.writeFileSync("/tmp/shutdown", "1");
console:dev:   28 |
console:dev:   29 |   setTimeout(() => {
console:dev: 
console:dev: A Node.js module is loaded ('node:fs' at line 26) which is not supported in the Edge Runtime.
console:dev: Learn More: https://nextjs.org/docs/messages/node-module-in-edge-runtime

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.0.0: Wed Sep 17 21:41:45 PDT 2025; root:xnu-12377.1.9~141/RELEASE_ARM64_T6000
  Available memory (MB): 65536
  Available CPU cores: 10
Binaries:
  Node: 25.1.0
  npm: 11.6.2
  Yarn: N/A
  pnpm: 10.20.0
Relevant Packages:
  next: 16.0.1
  eslint-config-next: N/A
  react: 19.2.0
  react-dom: 19.2.0
  typescript: 5.9.3
Next.js Config:
  output: standalone

Which area(s) are affected? (Select all that apply)

After

Which stage(s) are affected? (Select all that apply)

next dev (local)

Additional context

No response

extent analysis

TL;DR

The issue can be resolved by modifying the shutdown function to avoid using Node.js APIs and modules not supported in the Edge Runtime.

Guidance

  • Identify and replace the process.exit(0) call with an alternative that is compatible with the Edge Runtime.
  • Remove or refactor the const fs = await import("node:fs"); line, as the node:fs module is not supported in the Edge Runtime.
  • Consider using Edge Runtime-compatible APIs for shutdown and file operations.
  • Review the Next.js documentation on Edge Runtime limitations to ensure compliance.

Example

No code example is provided, as the necessary modifications depend on the specific requirements of the shutdown function and the Edge Runtime compatibility constraints.

Notes

The provided environment information and error messages indicate that the issue is related to the use of Node.js APIs and modules in the Edge Runtime, which has specific limitations. The solution will require adapting the code to work within these constraints.

Recommendation

Apply a workaround by refactoring the shutdown function to use Edge Runtime-compatible APIs and avoid unsupported Node.js modules, as the current implementation is not compatible with the Edge Runtime.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

nextjs - 💡(How to fix) Fix A Node.js module is loaded error in instrumentation.ts [1 comments, 2 participants]