Import syntax failing in package

I’m trying to run

import { checkNpmVersions } from 'meteor/tmeasday:check-npm-versions';

(from https://github.com/tmeasday/check-npm-versions) in a package I’m editing. This makes Meteor crash with

W20160316-10:16:17.001(-7)? (STDERR) import { checkNpmVersions } from 'meteor/tmeasday:check-npm-versions';
W20160316-10:16:17.001(-7)? (STDERR) ^^^^^^   
W20160316-10:16:17.018(-7)? (STDERR) SyntaxError: Unexpected reserved word`

Is it possible that it’s related to some package settings? btw how do I specify meteor version in package setting? api.versionsFrom('METEOR@1.3'); ?

You have to add the ecmascript package in order to use the import and export syntax.

For more information you can check the guide https://github.com/meteor/meteor/blob/release-1.3/packages/modules/README.md

1 Like

Unless it’s changed for 1.3 you can’t use ES2015 syntax in package.js files (@tmeasday, @sashko?).

thanks @jsep,

It worked like:

// package.js
Package.onUse(function (api) {
  api.versionsFrom('METEOR@1.0');

  api.use(["ecmascript"], ["client", "server"]);
  ...
  api.mainModule("server/startup.js", "server");
  ...

// server/startup.js
import { checkNpmVersions } from 'meteor/tmeasday:check-npm-versions';
checkNpmVersions({
  ...
});
... 

Where I have to add ecmascript and use api.mainModule instead of api.add_files

1 Like