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

🐛 BUG: relative imports from a nested main in base_dir breaks #6353

Open
GregBrimble opened this issue Jul 28, 2024 · 0 comments
Open

🐛 BUG: relative imports from a nested main in base_dir breaks #6353

GregBrimble opened this issue Jul 28, 2024 · 0 comments
Labels
bug Something that isn't working

Comments

@GregBrimble
Copy link
Member

Which Cloudflare product(s) does this pertain to?

Wrangler

What version(s) of the tool(s) are you using?

3.67.1 [Wrangler]

What version of Node are you using?

v20.9.0

What operating system and version are you using?

macOS 14.5 (23F79)

Describe the Bug

Observed behavior

- some/
  - base_dir/
    - nested/
      - index.js
    - foo.js
- wrangler.toml
./some/base_dir/nested/index.js
import { x } from "../foo.js";

export default {
fetch() {
return new Response(x);
}
}

./some/base_dir/foo.js
export const x = "Hello, world!";
./wrangler.toml
main = "./some/base_dir/nested/index.js"
base_dir = "./some/base_dir"
no_bundle = true
rules = [
  { type = "ESModule", globs = ["**/*.js"] }
]

npx wrangler dev collects foo.js as an additional module, but errors with

✘ [ERROR] service core:user:worker: Uncaught Error: internal error


✘ [ERROR] MiniflareCoreError [ERR_RUNTIME_FAILURE]: The Workers runtime failed to start. There is likely additional logging output above.

Expected behavior

I'm able to import from a parent when base_dir includes those modules.

I suspect what is happening is that we correctly attach additional modules with their relative path to base_dir (e.g. /foo.js), but the main entry path is being incorrectly set as /index.js rather than /nested/index.js, so relative imports from there are busted.

Steps to reproduce

As above.

Changing the import to import { x } from "/foo.js"; "fixes" the issue, hence my theory on how we're setting the current module path.

Please provide a link to a minimal reproduction

No response

Please provide any relevant error logs

No response

@GregBrimble GregBrimble added the bug Something that isn't working label Jul 28, 2024
@github-project-automation github-project-automation bot moved this to Untriaged in workers-sdk Jul 28, 2024
@petebacondarwin petebacondarwin moved this from Untriaged to Selected for Development in workers-sdk Jul 29, 2024
@lrapoport-cf lrapoport-cf moved this from Selected for Development to Backlog in workers-sdk Aug 19, 2024
@andyjessop andyjessop self-assigned this Oct 14, 2024
@andyjessop andyjessop removed their assignment Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that isn't working
Projects
Status: Backlog
Development

No branches or pull requests

2 participants