So I can't use ES6 with Meteor 1.3 afterall? - update: got it working

So I was excited to be able to use ES6 with Meteor 1.3 – I was hoping to make use of const and let, etc. So I wrote an NPM package that makes use of this stuff, installed it with npm into my meteor project, and now I get this error:

SyntaxError: Use of const in strict mode.

What gives?

If you’re writing your own npm package, you should probably use something like webpack and babel to allow you to transpile your code so it’s globally usable. Many people put their ES2015 code in a folder like src and have it build/transpile to a folder called lib or dist.

Yeah, that’s what I’m doing.

Do you have the ecmascript package installed?

No bundling system - Meteor, Webpack, etc - compiles NPM packages after they are installed. The practice on NPM is to compile packages before you publish them, and yes you basically have to set that up manually right now.

1 Like

Yes. I made a brand new meteor app and the only thing I have done so far is to try and include my NPM package (directly from my source). Apparently I’m not doing something exactly correctly. The ecmascript package was included my default and I see it when I type meteor list.

You can also use your own local npm package in Meteor by doing this:

$ cd /your/npm/package
$ npm run build # or whatever your build process is
$ npm link
$ cd /your/meteor/app
$ npm link my-npm-package

Thanks all. I was able to get it working. What I had to do was change this line in the package.json file of the npm package:

"main": "index.js",

to this:

"main": "dist/bundle.js",

I guess this allows Meteor to know how to use the version that has been transpiled with Babel.

1 Like