relative import of a `.js` file fails inside handlers
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 11.2k
- Forks
- 899
- Avg merge
- 2d 24m
- Merged PRs (30d)
- 40
Description
Environment
node: v18.18.0
nitropack: "2.9.6"
"express": "^4.19.2"
export default defineNitroConfig({
srcDir: 'server',
handlers: [
{
route: '/api',
middleware: true,
handler: './subsystem/index.ts',
},
],
});
Reproduction
https://stackblitz.com/edit/github-zqsihv?file=subsystem%2Froutes%2Fone.js
- have the defined
subsystem/index.tsimport a.jsrelatively
…
import oneRoute from './routes/one.js';
…
- run
dev - error message: \
[worker reload] Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/subsystem/routes/one.js' imported from /home/projects/yqniqmbba.github/.nitro/dev/index.mjs
Describe the bug
it looks like the module is resolved from the filesystem root when a relative import of a .js file is encountered. index.mjs contains file paths with too many ../. I expect them to be resolved correctly, like .ts files.
https://github.com/nuxt/nuxt/issues/26150
Additional context
either removing srcDir or changing one.js to one.ts fixes the issue in the minimal example. only dev mode is affected, using build && preview, it runs fine.
Logs
No response
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 with the minimal StackBlitz reproduction and the generated .nitro/dev/index.mjs, using server/subsystem/index.ts and subsystem/routes/one.js as the import path. Run dev with srcDir set to server and compare the generated relative paths for .js and .ts imports. Done means the .js handler import resolves correctly in dev mode without changing the source extension; build and preview already work.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, typescript
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100