Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Error message less-than-optimal when instrumentation cannot be loaded #78457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ace130-github opened this issue Apr 23, 2025 · 1 comment · May be fixed by #78458
Open

Error message less-than-optimal when instrumentation cannot be loaded #78457

ace130-github opened this issue Apr 23, 2025 · 1 comment · May be fixed by #78458
Labels
Instrumentation Related to Next.js Instrumentation. Runtime Related to Node.js or Edge Runtime with Next.js.

Comments

@ace130-github
Copy link

ace130-github commented Apr 23, 2025

Link to the code that reproduces this issue

https://codesandbox.io/p/devbox/pensive-feynman-lfsfss?file=%2Finstrumentation.ts

To Reproduce

  1. Start the application (npm run dev)
  2. Watch the console output.

Current vs. Expected behavior

Console output says:

$ next dev
   ▲ Next.js 15.4.0-canary.5
   - Local:        http://localhost:3000
   - Network:      http://172.17.0.2:3000

 ✓ Starting...
 ✓ Compiled /instrumentation in 573ms (22 modules)
[TypeError: Cannot set property message of [object Object] which has only a getter]

It is correct behaviour that an error occurs since the file instrumentation.ts results in an error when loaded.

Problem is that the actual error (in our case a zod error that occurs when the environment is parsed) is discarded, and a TypeError with no hint towards the actual error is thrown instead.

Reason is line 479 in next-dev-server.js:

    async loadInstrumentationModule() {
        let instrumentationModule;
        if (this.actualInstrumentationHookFile && await this.ensurePage({
            page: this.actualInstrumentationHookFile,
            clientOnly: false,
            definition: undefined
        }).then(()=>true).catch(()=>false)) {
            try {
                instrumentationModule = await require((0, _path.join)(this.distDir, 'server', _constants.INSTRUMENTATION_HOOK_FILENAME));
            } catch (err) {

                // Here is the error:
                err.message = `An error occurred while loading instrumentation hook: ${err.message}`;

                throw err;
            }
        }

This line assumes hat the message property of the received error is writable, which may not be the case.

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Pro
  Available memory (MB): 28381
  Available CPU cores: 16
Binaries:
  Node: 22.10.0
  npm: 10.9.0
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 15.3.0 // There is a newer version (15.3.1) available, upgrade recommended! 
  eslint-config-next: 15.3.0
  react: 19.1.0
  react-dom: 19.1.0
  typescript: 5.8.3
Next.js Config:
  output: standalone
 ⚠ There is a newer version (15.3.1) available, upgrade recommended! 
   Please try the latest canary version (`npm install next@canary`) to confirm the issue still exists before creating a new issue.
   Read more - https://nextjs.org/docs/messages/opening-an-issue

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

Instrumentation, Runtime

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

next dev (local)

Additional context

No response

@github-actions github-actions bot added Instrumentation Related to Next.js Instrumentation. Runtime Related to Node.js or Edge Runtime with Next.js. labels Apr 23, 2025
@ace130-github
Copy link
Author

PR: #78458

@ace130-github ace130-github linked a pull request Apr 23, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Instrumentation Related to Next.js Instrumentation. Runtime Related to Node.js or Edge Runtime with Next.js.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant