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

Multiple const mod = definitions? #136

Open
jflatow opened this issue Sep 8, 2023 · 3 comments
Open

Multiple const mod = definitions? #136

jflatow opened this issue Sep 8, 2023 · 3 comments

Comments

@jflatow
Copy link

jflatow commented Sep 8, 2023

I'm bundling up some files and ending up with several definitions of const mod. Sometimes its a function that returns the exports from an imported module, and other times it's the exports directly. Is this a known issue, and if so, is there any workaround?

@jflatow
Copy link
Author

jflatow commented Sep 8, 2023

Ok, I believe I tracked this down to an issue with eval, which I know is evil, but still part of the language. I noticed that there can be various issues when bundling code with eval in it, but I've created a minimal example which reproduces the one I am reporting here (multiple mod definitions).

Consider three files: multi-mod.A.ts, multi-mod.B.ts, and multi-mod.importer.ts:

export class A {}
export class B {}
import * as m1 from './multi-mod.A.ts';
import * as m2 from './multi-mod.B.ts';
const { A } = m1;
const { B } = m2;
eval('');

If you bundle the importer script, you get multiple definitions of mod.

If you remove B from the picture you can see a different but related issue that Identifier 'A' has already been declared.

@jflatow
Copy link
Author

jflatow commented Sep 8, 2023

As a workaround for anyone else running into this issue: you can replace eval with window.eval if the code doesn't need access to local state.

@jflatow
Copy link
Author

jflatow commented Sep 9, 2023

There's a separate but related bug if you export the name mod in user-space code yourself, the emitted module gets overwritten.

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

No branches or pull requests

1 participant