This release is mostly just bug fixes.
CommonJS <> ESM interop reliability improvements
Bun now preserves the behavior of live bindings when referencing bundled symbols. This fixes a number of subtle bugs in different packages.
This also updates the preferred extension order depending on how code is imported. Previously, .mjs
files were ignored and that was silly. Now, when you use import
and the path has no file extension, Bun will attempt to load .mjs
or .mts
before trying .js
or .cjs
// CommonJS or `require`, `require.resolve`
// configurable via --extension-order CLI flag
pub const ExtensionOrder = [_]string{
".tsx",
".ts",
".jsx",
".cts",
".cjs",
".js",
".mjs",
".mts",
".json",
};
// ES Modules or `import`
pub const ModuleExtensionOrder = [_]string{
".tsx",
".jsx",
".mts",
".ts",
".mjs",
".js",
".cts",
".cjs",
".json",
};
Template literal parsing bug
Before, this code caused an assertion failure in Bun's JavaScript parser due to the function being defined in the template tag:
import styled from 'styled-components'
export const HoverableBox = styled.div.attrs<{
disabled?: boolean
}>(({ disabled }) => ({
cursor: disabled ? undefined : 'pointer',
}))<{ disabled?: boolean }>`
${({ disabled }) => (disabled ? 'pointer-events: none;' : '')}
`
The problem was related to when scopes for template literal tags were visited. This has been fixed.
try
& require()
Previously, this code would produce a build error:
try {
require("this-package-should-not-exist");
} catch (exception) {}
try {
await import("this-package-should-not-exist");
} catch (exception) {}
import("this-package-should-not-exist").then(
() => {},
() => {}
);
In each of these cases, errors are caught at runtime, so it should not produce a build error.
Top-level await is now enabled
Top-level await will no longer error when targeting browsers, however you should know that since Bun does not transpile for backwards compatibility, you will need to be sure it is safe to use in the target environment.
Using module.exports
with top-level await is undefined behavior