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

Include file extension in generated import specifiers #59

Closed
wants to merge 1 commit into from

Conversation

developit
Copy link

@developit developit commented May 26, 2022

What:

This outputs imports like import { pure } from "./pure.mjs"

Why:

This change should fix vitest-dev/vitest#1375.

ES Module specifiers are URLs with no implied extension or index file resolution. Tools like Vite relax this to allow CommonJS-style ./index.js resolution, but it's better to avoid relying on this since it's unspecified behavior.

How:

This uses the --out-file-extension option that was added to @babel/cli in version 7.8.0. It allows specifying a filename extension to use for generated import specifiers.

Checklist:

  • N/A Documentation added
  • N/A Tests
  • N/A Typescript definitions updated
  • Ready to be merged

This outputs imports like `import { pure } from "./pure.mjs"`
@JoviDeCroock
Copy link
Member

JoviDeCroock commented May 26, 2022

I have quickly tried to do this in my example linked in the issue which results in the same issue.

  • I removed all .js files
  • Replaced the imports to have .mjs extensions
  • Replaced it in the pkg.json import maps

Which still results in them being unfound for me 😅 doing the exact same thing with .js works perfectly but in turn seems to break Node (unless we add type module but then the cjs folder breaks)

@JoviDeCroock
Copy link
Member

Closing as superseded by #60

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

Successfully merging this pull request may close these issues.

Importing .mjs breaks leaf imports
2 participants