vercel / vercel/next.js

Next.js Instrumentation can not import and resolve the node-bindings module.

Open
#64,471 10 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Instrumentation
Dominant language
JavaScript
Stars
142k
Forks
32.4k
Avg merge
2d 14h
Merged PRs (30d)
351

Description

Link to the code that reproduces this issue

https://github.com/bugs-report/nextjs-issue-64471

To Reproduce

First, install a node-binding package, like the @napi-rs/tar, which provides the rust bindings and .node bytecode module.

npm i @napi-rs/tar

And then enable the next.js instrumentation with the official document

In next.config.js

/** @type {import("next").NextConfig} */
const nextConfig = {
  reactStrictMode: true,
  experimental: {
    instrumentationHook: true,
  },
};

module.exports = nextConfig;

In instrumentation.ts, import the node-binding module

import tar from '@napi-rs/tar';

export function register() {
  console.log(tar.Entry)
}

Then run project in dev, it crashed

 ✓ Starting...
 ○ Compiling /instrumentation ...
 ⨯ ./node_modules/@napi-rs/tar-win32-x64-msvc/tar.win32-x64-msvc.node
**Module parse failed: Unexpected character '�' (1:2)**
**You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders**
(Source code omitted for this binary file)

Import trace for requested module:
./node_modules/@napi-rs/tar-win32-x64-msvc/tar.win32-x64-msvc.node
./node_modules/@napi-rs/tar/index.js
Error: An error occurred while loading instrumentation hook: Cannot find module 'E:\frontend-projects\reproduction-app\.next\server\instrumentation'
Current vs. Expected behavior

It should import the node-bindings module in instrumentation.ts

Provide environment information
Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 10 Pro
  Available memory (MB): 36670
  Available CPU cores: 8
Binaries:
  Node: 20.10.0
  npm: N/A
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 14.2.1-canary.4 // Latest available version is detected (14.2.1-canary.4).
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.1.3
Next.js Config:
  output: N/A
Which area(s) are affected? (Select all that apply)

Not sure

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

next dev (local)

Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked reproduction repository, next.config.js, and instrumentation.ts, then run the documented next dev setup with @napi-rs/tar. Trace how the instrumentation hook compiles and resolves the native .node module, using the reported webpack parse error as the failure point. Done means the import works in instrumentation.ts without the module parse or instrumentation loading errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
nextjs, node.js, typescript, webpack
Domain
backend, build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.