-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Description
Bug Report
- I would like to work on a fix!
Current behavior
TypeError: Cannot redefine property: c
Namespace reexports are transpiled like this:
for(key ...){
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return imported[key];
}
});
}But the spec allows for reexporting a symbol twice in the same file if it is actually the same binding (see example code below).
This means that Object.defineProperty(exports, "c", ...) is called twice, causing the error.
One of the packages that do this is @fluentui/react (this came up in parcel-bundler/parcel#4399)
Input Code
- https://github.com/mischnic/parcel-issue-4399 (
lib/already contains the Babel output ofsrc-valid)
export * from "./a.js";
export * from "./b.js";
// ---- everything below is just for context ---
// a.js
export { c } from './c.js'; // <--
export const a = "a";
// b.js
export { c } from './c.js'; // <--
export const b = "b";
// c.js
export function c() {
return false;
}Expected behavior
The first file should export a, b, c (and not throw).
Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)
babel --plugins @babel/plugin-transform-modules-commonjs --delete-dir-on-start src-valid -d libEnvironment
System:
OS: macOS 10.15.4
Binaries:
Node: 14.4.0 - /usr/local/bin/node
Yarn: 1.22.4 - /usr/local/bin/yarn
npm: 6.14.4 - /usr/local/bin/npm
npmPackages:
@babel/cli: ^7.10.1 => 7.10.1
@babel/core: ^7.10.2 => 7.10.2
@babel/plugin-transform-modules-commonjs: ^7.10.1 => 7.10.1
Possible Solution
Not use Object.defineProperty? configurable: true ? But all of these have other sideffects
Additional context
Technically, f there are conflicting reexports (see src-invalid), there should be a SyntaxError (!).
But even Rollup doesn't handle this correctly (and Babel cannot work across multiple files anyway). rollup/rollup#3629