vsivsi/meteor-file-collection

The global definition of Mongo.Collection has changed since the file-collection package was loaded.

g41n opened this issue · 3 comments

g41n commented

Hi to all,
this is the error I have replacing CFS with FC in an existing application:

gridFS_client.coffee:16
Uncaught Error: [The global definition of Mongo.Collection has changed since the file-collection package was loaded. Please ensure that any packages that redefine Mongo.Collection are loaded before file-collection.]

I don't know how meteor imports packages, if the order is in .meteor/packages FC is the last one.

I've also found that build packages are in .meteor/local/build/programs/web.browser/packages/ and, in alphabetical order, only webapp is after FC:

[...]
underscore.js
underscore.js.map
vsivsi_file-collection.js
vsivsi_file-collection.js.map
webapp.js
webapp.js.map

Other things I can check to verify the inclusion order?

Meteor version is 1.3.3.1

Any hint would be appreciated.
Thanks in advance :)

Hi, yes, Meteor no longer provides any guarantees regarding package load order for packages that don't explicitly depend on one another. file-collection doesn't depend on any package that replaces the default Mongo.Collection object provided by Meteor. And it really can't because there are many such packages, with new ones probably being created all the time (or rather, new packages that depend on such packages). The only way file-collection could be made completely safe would be for it to depend on all other packages which is clearly untenable.

The solution? Don't use packages that Monkey patch or replace the objects that define the Meteor API. The check you've run into was added to this package to protect everyone's sanity. If Mongo.Collection is being modified by other packages in unpredictable ways, then I can't provide or reasonably support any standard of compatibility or data integrity for file-collection.

There's a long history for this issue, and it all stems from other packages (that provide useful functionality) being implemented using a terrible anti-pattern. It sucks, but it's not a problem I can fix. Here's a trail of tears for you to follow if you want to fully appreciate how messed up this is for Meteor:

meteor/meteor#6416
https://github.com/vsivsi/meteor-defender
vsivsi/meteor-file-sample-app#2 (comment)
#61
#125
vsivsi/meteor-job-collection#97

I had this issue, but moving vsivsi:file-collection to the end of the package list resolved it, at least for me.

Thank u @dpatte !