-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
[Feature]: Add .js
file extension to built output to improve native ESM support
#30634
Comments
@miroslavstastny I'm re-assigning this to v-build as we will be shipping it |
Update:
Approach options:1. adding explicit
👁️ This has following gotchas: We need to enforce that relative imports always point to existing physical file no matter what module loader is in place (node vs browser). 🧪 Example: // @filename src/index.ts
export {Hi} from './hello'
// @filename src/hello/index.ts
export {Hi} from './hi' ⬇️ swc transpile ( + @swc/plugin-transform-imports ) ⬇️ // @filename lib/index.js
// 🚨🚨🚨 this is invalid path - will throw in all environements
export {Hi} from './hello.js'
// @filename src/hello/index.js
export {Hi} from './hi.js' Rollup handles this as expected // @filename src/index.ts
export {Hi} from './hello'
// @filename src/hello/index.ts
export {Hi} from './hi' ⬇️ rollup ⬇️ // @filename lib/index.js
// ✅ ✅ ✅ unwraps the import path to it's source
export {Hi} from './hello/hi.js'
// @filename src/hello/index.js - wont be created
// ✅ ✅ ✅ nested barrel files are completely removed from output as their are not necessary What are our implementation options:
2. declaring package as ESM native via
3. shipping all ESM files with By default in ESM native environments, if a package.json has no While we have export maps in place, they are invalid for native ESM loader ( it works solely for build tools with current output ). In order to support native ESM loader without making the package native ESM, all files that are accessed via
Implementation requirements:
1. adding explicit
2. declaring package as ESM native via
3. shipping all ESM files with
|
Re-opening since we had to revert this in #30803 |
I need it. When do you plan to fix it |
@spmonahan @Hotell Any update on above issue as i am also getting same issue |
Library
React Components / v9 (@fluentui/react-components)
Describe the feature that you would like added
I want Fluent's ESM output (CJS can go either way I think) to include the
.js
extension for all relative JS imports. For example,This update will better allow Fluent's ESM output to be loaded directly in the browser (import maps will still be required to resolve bare package imports but that's no problem).
Ideally we should do this without changing source code and leverage something like SWC's
@swc/plugin-transform-imports
(which transforms exports in addition to imports despite the name).Have you discussed this feature with our team
@Hotell @chrisdholt
Additional context
Currently the ESM output from Fluent is "extensionless" which prevents the ESM output from working correctly in a browser.
In this example there is a "bare module" import where code is imported from a package name (that lacks a
.js
extension) and a "bare JS file" import. The latter is typically used within a package to import other JS files using relative paths.We can address "bare modules" with importmaps, allowing
import $whatever from 'some-module-without-an-extension'
to resolve correctly but importmaps cannot, effectively†, handle the internal bare JS imports. To handle the bare JS imports we must update the output to include the.js
extension.† I say effectively because it is possible to generate an importmap for all the base JS imports within a package but such an importmap would be quite large and then require end users to correctly merge it with any other importmaps they are using. Technically possible but not a good solution :)
Related issues
Validations
Priority
Normal
The text was updated successfully, but these errors were encountered: