Skip to content
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

relative import of a .js file fails inside handlers #2434

Open
pixunil opened this issue May 11, 2024 · 0 comments
Open

relative import of a .js file fails inside handlers #2434

pixunil opened this issue May 11, 2024 · 0 comments

Comments

@pixunil
Copy link

pixunil commented May 11, 2024

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

  1. have the defined subsystem/index.ts import a .js relatively
…
import oneRoute from './routes/one.js';
…
  1. run dev
  2. 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.

nuxt/nuxt#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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant