-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Duplicate fireEvent export creates Rollup warnings #790
Comments
This is a major bummer. I'm not a fan of any of those solutions. I was unaware of this limitation in the spec. Do you have a link to the specification about this? I'll suggest a 4th solution: Use So I think we have a good solution, but I'd like to be sure that the spec really does require this before we go that route. |
Oh, also, thank you for bringing this to our attention @FredKSchott :) |
That really would be a bummer. I just tried this with node 14.12.0 and had no issues. Though interestingly the order of the exports didn't matter. It always used the "nearest" (dependency tree depth) method. // run.mjs
import { main } from './index.mjs';
console.log(main());
// index.mjs
export * from './module.mjs';
export function main() {
return 'index';
}
// module.mjs
export function main() {
return 'module';
}
I quickly scanned https://tc39.es/ecma262/#sec-exports. The only references to duplicates are:
But that refers to a single statement. So
That would be function main() {}
export {main}
export {main} I was under the impression that Node implements ES Modules by now. What are bundler folks using to test ES module semantics (browsers, node flags etc)? |
I do believe this is a violation of the specification – in particular of this rule under section 15.2.1.1:
I understand the specification as follows:
If we have files // star export vs direct export
export * from './foo';
export const a = 2;
// re-export vs direct export
export { a } from './foo';
export const a = 2;
// star export vs re-export
export * from './foo';
export { a } from './bar'; Of these, both I believe that this must be fixed to conform to the specification. |
Thanks everyone for adding detail here! You're right, it looks like Chrome also ignores a conflict. So it sounds like on our end, the Rollup warning that we're seeing is more aggressive than it needs to be for real-world use today. If all other environments support this, we'll probably resolve this on our end more broadly by silencing this warning in Snowpack. My first impression from all of the spec links above is that this is undefined behavior / not explicitly prohibited. pinging @MylesBorins as well since I know Node is getting close to an ESM deadline for Node v12 LTS, in case Node's behavior here is unintentional. |
I think this doesn't error because for 1
-- https://tc39.es/ecma262/#sec-exports-static-semantics-exportednames |
FWIW, if decisions are being made about whether to include this use case in the spec, I can say from real-world standpoints that making this permissible by the spec would be extremely useful and it would be a real shame if the spec explicitly disallowed this. It would likely lead to unexpected breakages the go way beyond Testing Library... |
I've seen this syntax cause an error in some tooling before, maybe an older version of Flow or something? As for impact, we'd have to rethink our re-exports within RTL and our documentation for "custom render" modules. |
@FredKSchott Is this still an issue in latest versions of snowpack? Shouldn't we move this to the snowpack repository instead? So far snowpack is the first environment (transpiling or implementing ES modules) where we heard of this issue. Considering that my interpretation of the spec allows this pattern and it worked so far for us it seems like this is a snowpack issue not testing-library issue. |
Yes! This is safe to close here as valid ESM, and we added a workaround to handle this on our end already. |
@testing-library/react
version: latestRelevant code or config:
https://github.com/testing-library/react-testing-library/blob/master/src/pure.js#L118-L120
What you did:
Bundled this package with Rollup via Snowpack.
What happened:
Problem description:
fireEvent
is exported twice out of the@testing-library/react
package: once directly, and then once indirectly via anexport *
invocation (see link above).This is invalid ESM that will break in pure ESM environments (ex: Node) and create warnings in others (Snowpack, Rollup, etc).See convo below.Suggested solution:
Ref: https://developer.mozilla.org/en-US/docs/web/javascript/reference/statements/export
fireEvent
function asfireReactEvent
instead, preventing conflict.The text was updated successfully, but these errors were encountered: