Automatically add nitro module paths to be inlined
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 11.2k
- Forks
- 899
- Avg merge
- 2d 24m
- Merged PRs (30d)
- 40
Description
Environment
Node v20.9.0, Nitropack 2.10.4
Reproduction
https://github.com/cjpearson/nitro-externals-test
To reproduce:
- Inside
nitro_module/, runyarn install && yarn unbuild - Inside
nitro_app, runyarn install && yarn dev
Describe the bug
When adding a server handler through a module, if there are relative imports within the handler, it will crash in dev mode.
For example, the following will work in the prod build but fail with [cause]: Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/nitro-module/dist/runtime/utils/greeting.mjs' in dev.
import { defineEventHandler } from 'h3'
import { sayHello } from '../utils/greeting'
export default defineEventHandler((event) => {
return sayHello()
})
This is a common issue reported with Nuxt, but is also reproducible with a pure nitro module.
https://github.com/nuxt/nuxt/issues/18909
https://github.com/nuxt/nuxt/issues/26150
There is a workaround described here, but with a large module the number of paths becomes quite large and it's easy to miss one as missing one does not guarantee a build error.
Additional context
No response
Logs
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the failure with the commands in nitro_module/ and nitro_app/, focusing on the server handler's relative import from ../utils/greeting. Trace how module paths are handled in dev mode versus the production build. Done means module-provided relative imports are automatically inlined and the dev server no longer raises ERR_MODULE_NOT_FOUND.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, typescript
- Domain
- backend, build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100