Skip to content

[Nuxt/SolidStart] Nitro-based frameworks are not tracing on server-side (Cannot find module hook.js) #17778

@s1gr1d

Description

@s1gr1d

Problem: Cannot find module hook.js

When setting debug: true, you can see the following error when starting the application:

Sentry Logger [warn]: Failed to register ESM hook Error: Cannot find module './hook.js'
Require stack:
- /[...]/app-dir/.output/server/node_modules/import-in-the-middle/hook.mjs
   .....

import-in-the-middle is missing the hook.js file in the folder and thus is not able to import it.

Why the file is missing - Node File Trace

Both files (hook.mjs and hook.js) are included in node_modules/import-in-the-middle of the root directory. Nitro uses @vercel/nft to trace the files from the node_modules to include only the needed ones in the node_modules of the build output.

The file is missing in .output/server/node_modules/import-in-the-middle. The folder should contain a hook.js and a hook.mjs file, but only the hook.mjs file is there.

Changes in import-in-the-middle version 1.14.3

The import was changed from

  • import { createHook } from './hook.js' to
  • const { createHook } = require('./hook.js') (PR diff here)

and it seems like @vercel/nft does not trace and include files imported with require (from createRequire(import.meta.url). This file is needed to make tracing work on the server-side.

Upcoming Fix

It looks like @vercel/nft only looks for the exact string of module.createRequire and there is an upcoming fix in import-in-the-middle which will change it in a way so it can get picked up by @vercel/nft.

nodejs/import-in-the-middle#207

Workaround

This is something that most possibly @vercel/nft needs to fix and for now you can add a version override to use an older version:

// npm
"overrides": {
  "import-in-the-middle": "1.14.2"
}
// yarn
"resolutions": {
  "import-in-the-middle": "1.14.2"
}
// pnpm
"pnpm": {
  "overrides": {
    "import-in-the-middle": "1.14.2"
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions