I just debugged this in Chrome Dev Tools. The problem is there are two collections.ts
. Now I am not sure why. It is related to webpack, which I don’t understand if i’m honest.
If anyone could advise, I would appreciate it.
Please see the following for more details.
Have you confirmed for yourself that the error is on the client-side (browser) and not on the server-side (server/api)?
I don’t know what webpack is or does (beyond reading “what is webpack”), but I am surprised to see it in the browser listing files in api/server/
. Files in the Meteor server folder should only be accessible to the server.
Do both collection.ts
files look complied into JS instead of the original TS?
Hi,
Yes it must be the two collections.ts
.
There is only one collections.ts
, but when it runs, I can see there are two from Dev Tools.
/theWhoZoo/api/server/collections.ts
So it must be something to do with the compilation, that at run time there are two.
It looks like the error is only on the client. I have a test utility that calls the server code, and it invokes it with no errors.
I can fin that it is called from:
theWhoZoo/www/build/js/app.bundle.js.map
..."webpack:///./api/server/collections.ts?97d5"...
I tried deleting this file, but it just gets regenerated from ionic serve
.
I’m not sure that the problem is with 2x collections.ts
because that only exports the collections. If the collections are considered as exported in the same module, then the second exports should simply overwrite the first. If the collections are considered as different modules, then it should take 2 import calls to end up with both. And 2 import calls to the same module would also result in the There is already a collection named "chats"
error. So the question is “In exactly which code context does the duplicate call, and thus the error, occur?”.
You’ve narrowed it down to the client, which is good. I’d throw a console.log('exports collections');
as the last line in collections.ts
so you can count how many time that runs, and also throw a console.log('filename'); console.log(Chats);
as the first line of every file which imports Chats
so you can see which file(s) already have Chats
defined before importing it (again, and probably causing the error).
I’d expect to see the error happen immediately after either:
- [Filename]
Mongo.Collection {…}
Error
- [Filename]
undefined
exports collections
exports collections
Error
You should be able to resolve the former by removing the extraneous import statement from the file (and restart the app with the logging still in place to see if additional files trip or if the import is somehow duplicated in one calling context but not in another). I don’t know what to try to resolve the second as that would definitely be a problem with Ionic / TS / Webpack etc.; I used none of those before.
I just managed to solve it.
SOLUTION:
By making node_modules a symbolic link, i.e. only having one node_modules, fixed this.
I think having two node_modules resulted in 2x collections.
I appreciate all your help here.
2 Likes
You are welcome. I’m glad you found a solution and thanks for posting what it was!