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

[ERROR] Identifier Meteor has already been declared #10234

Closed
elmarti opened this issue Sep 23, 2018 · 5 comments
Closed

[ERROR] Identifier Meteor has already been declared #10234

elmarti opened this issue Sep 23, 2018 · 5 comments
Assignees
Milestone

Comments

@elmarti
Copy link

elmarti commented Sep 23, 2018

  • Occurring in Meteor 1.7.x
  • Did not occur in Meteor 1.6.x
  • Present on Ubuntu and Windows 10

In my elmarti:video-chat package, I previously had both app.addFiles and app.mainModule calls for the same file in package.js, I may have done this through lack of understanding, but it now causes the file to be bundled twice, meaning that there are duplicate let declarations.

But now this seems to cause the non-fatal error
[ERROR] Identifier Meteor has already been declared

@elmarti
Copy link
Author

elmarti commented Sep 24, 2018

Removing the import { Meteor } from 'meteor/meteor'; in meteor.js seems to fix this particular issue, but then causes the same thing for MeteorClient.. is module scoping broken?

@elmarti
Copy link
Author

elmarti commented Sep 24, 2018

Alright, I seem to have found the issue, it was using api.addFile and api.mainModule for the same file, which now causes the code to be added to the file twice, causing variable name collisions.

My guess would be that the modules appear to be loading asynchronously now, so it allows the browser to resolve the modules at runtime, whereas I assume before, the compiler picked up that the same module was being loaded twice and dealt with it in its own way.

I won't close, on the off-chance you want to give your opinion

@elmarti
Copy link
Author

elmarti commented Sep 24, 2018

BTW, DI pattern was a red herring, this is a general bundling issue which has brought a sleeping bug to life, rather than something specific to my design pattern.

elmarti pushed a commit to elmarti/meteor-video-chat that referenced this issue Sep 24, 2018
@elmarti elmarti changed the title [ERROR] Identifier Meteor has already been declared when using DI pattern [ERROR] Identifier Meteor has already been declared Sep 25, 2018
@benjamn benjamn added this to the Release 1.8 milestone Sep 26, 2018
@benjamn benjamn self-assigned this Sep 26, 2018
@benjamn
Copy link
Contributor

benjamn commented Sep 26, 2018

I believe the reason this started happening in Meteor 1.7 is that the modern bundle now compiles the import { Meteor } from "meteor/meteor" down to a let declaration instead of var, and you can't have two let Meteor declarations in the same scope.

In any case, it seems like a bug that adding the same file with api.addFiles and api.mainModule results in multiple copies of the module, since those api method calls should just be idempotent.

benjamn added a commit that referenced this issue Oct 3, 2018
This would have helped catch the underlying problem in #10234.
@benjamn
Copy link
Contributor

benjamn commented Oct 3, 2018

I've added a warning about duplication between api.addFiles and api.mainModule. There was already a warning in api.addFiles, so it was just a matter of adding the same warning to api.mainModule. Hopefully this will help catch similar problems in the future!

@benjamn benjamn closed this as completed Oct 3, 2018
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

2 participants