4

import {Mongo} from 'meteor/mongo'; export let Products = new Mongo.Collection('products');

above code is that I've written in my sample project. When I try to run this sample project, It throws error

There is already a collection named "products"

I've tried meteor reset. still I am facing same issue. I googled but got no proper solution. can anyone help me out?

Vivek Aasaithambi
  • 919
  • 11
  • 23
  • I read a post from someone else somewhere who had the same problem and couldn't find out what exactly happens. He finally came to the solution that meteor will compile the typescript code and minifies it. If you now use an auto compiling IDE you will have copies of the same javascript on your server which triggers the error. Maybe try to switch your IDE to something else (e.g. [Atom](https://atom.io/)) – KRONWALLED Jul 05 '16 at 14:20
  • I am already using atom only :( – Vivek Aasaithambi Jul 05 '16 at 18:53

1 Answers1

2

I had the same issue the last days. I solved it using this part of my tsconfig.json

"atom": {
    "rewriteTsconfig": true
  },
  "compileOnSave": false,
  "buildOnSave": false,
  "compilerOptions": {
    "experimentalDecorators": true,
    "module": "commonjs",
    "target": "es5",
    "isolatedModules": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "removeComments": false,
    "noImplicitAny": false,
    "sourceMap": true
  },
  "filesGlob": ...

And i also deleted all .js and .js.map files from my working directory. As @KRONWALLED already mentioned, the problem is occuring when you use an IDE which is auto compiling your .ts files. When you are using the atom-typescript package it could be that this is autocompiling your .ts files. That's why you get this error. The important line in the tsconfig.json file is

"compileOnSave": false,

Here we declare that our compiler should not compile the file on save. Only when meteor is running, then the files get compiled with meteor.

I hope this will help you.

grahan
  • 2,148
  • 5
  • 29
  • 43
  • Hi Grahan, I am facing the same problem. Thank you for the advise. I have updated my `tsconfig.json`, but where is the **working directory** that needs the `.js` and `.js.map` files delete? – Richard Sep 12 '16 at 15:21
  • It should be the directory where the .ts file is located. – grahan Sep 12 '16 at 17:56