Trouble with importing local npm package: 'Unexpected reserved word'

I’m having trouble using local npm packages. I created a small test-app to debug the problem:
I have a local package folder my-package with a package.json:

{
  "name": "my-package",
  "version": "1.0.3",
  "description": "",
  "module": "src/index.js"
}

and a src folder with two files, myPackage.js :

export const myPackageLog = function () {
	console.log('logged from my-package')
}

and index.js :


export { myPackageLog } from './myPackageLog'

I have a meteor app with a with just one file in the server folder main.js :

import { myPackageLog } from 'my-package/src'
myPackageLog()

and a package.json :

{
  "name": "my-app",
  "private": true,
  "scripts": {
    "start": "meteor run"
  },
  "dependencies": {
    "meteor-node-stubs": "~0.2.0",
    "babel-runtime": "6.18.0",
    "my-package": "file:///Users/willem/meteor/my-package"
  }
}

This is what happens when I run the app (using Meteor 1.4.2.3) :

[[[[[ ~/meteor/my-app ]]]]]                   

=> Started proxy.                             
=> Started MongoDB.                           
W20170205-10:48:56.794(1)? (STDERR) packages/modules.js:331
W20170205-10:48:56.844(1)? (STDERR) export { myPackageLog } from './myPackageLog'
W20170205-10:48:56.845(1)? (STDERR) ^^^^^^
W20170205-10:48:56.845(1)? (STDERR) 
W20170205-10:48:56.846(1)? (STDERR) SyntaxError: Unexpected reserved word
W20170205-10:48:56.846(1)? (STDERR)     at Object.exports.runInThisContext (vm.js:53:16)
W20170205-10:48:56.847(1)? (STDERR)     at /Users/willem/meteor/my-app/.meteor/local/build/programs/server/boot.js:289:30
W20170205-10:48:56.847(1)? (STDERR)     at Array.forEach (native)
W20170205-10:48:56.848(1)? (STDERR)     at Function._.each._.forEach (/Users/willem/.meteor/packages/meteor-tool/.1.4.2_3.1edq869++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11)
W20170205-10:48:56.848(1)? (STDERR)     at /Users/willem/meteor/my-app/.meteor/local/build/programs/server/boot.js:128:5
W20170205-10:48:56.849(1)? (STDERR)     at /Users/willem/meteor/my-app/.meteor/local/build/programs/server/boot.js:344:5
W20170205-10:48:56.849(1)? (STDERR)     at Function.run (/Users/willem/meteor/my-app/.meteor/local/build/programs/server/profile.js:480:12)
W20170205-10:48:56.850(1)? (STDERR)     at /Users/willem/meteor/my-app/.meteor/local/build/programs/server/boot.js:343:11
=> Exited with code: 1

NPM packages aren’t built by the build tool the same way that Meteor packages that include the ecmascript package are. NPM packages have to be built before they are published. This post may help.

1 Like

Ah, I see, thanks!
I guessed that having a “module” property in the package’s package.json in stead of a "main" property should be an indicator to the build system that the package code is a real ES6 module and so should be processed differently.
In some package I also sometimes see the property '"jsnext:main": "./index.es.js"
Do you know what the reason is for all these different entry point specs?
I have never used another build tool than meteor. Do other build tools behave differently in this respect?

The jsnext:main is used by rollup, a module builder.

Yeah almost every build tool has a different way of handing this. I thought meteor did support the ES module format though, we should as @benjamn