Meteor cannot find re-exported module

I am writing a Meteor application using ES6, and I have a number of sub-components that I want to keep as separate npm packages. I have a library called frog-utils, which is shared across all packages, and which contain common helper functions.

When I try to re-export a module in frog-utils, it works fine with plain node, but Meteor complains that:

  • Gulp watch multiple folders
  • In React project, “this” converts into “undefined”
  • babel-node doesn't recognize es2015?
  • Trying to setup tests with mocha, babel & es6 modules
  • How to run Node.js app with ES6 features enabled?
  • Update: Errors with postCSS and Babel in Gulpfile
  • W20161114-10:12:17.483(1)? (STDERR) Error: Cannot find module './color_range'
    W20161114-10:12:17.484(1)? (STDERR)     at require (packages/modules-runtime.js:109:19)
    W20161114-10:12:17.484(1)? (STDERR)     at meteorInstall.node_modules.frog-utils.dist.index.js (packages/modules.js:17407:20)
    

    (Here’s an example from plain node, in the same directory)

    ~/s/F/frog (ac-collab) $ node
    > frogutils = require('frog-utils')
    { color_range: [Getter],
      uuid: [Function: uuid],
      currentDate: [Function: currentDate],
      booleanize: [Function: booleanize],
      shorten: [Function: shorten],
      compose: [Function: compose],
      composeReducers: [Function: composeReducers],
      notEmpty: [Function: notEmpty],
      identity: [Function: identity],
      getKey: [Function: getKey] }
    

    I’m writing in ES6, using Babel to create the output files which are exposed by the module, and the ES5 seems fine to me:

    var _color_range = require('./color_range');
    
    Object.defineProperty(exports, 'color_range', {
      enumerable: true,
      get: function get() {
        return _interopRequireDefault(_color_range).default;
      }
    });
    

    (Here’s the ES6 line I use)

    export {default as color_range} from './color_range'
    

  • Module Build Failed - Webpack, React, Babel
  • Why is the 'this' not able to resolve within the service in AngularJS?
  • Using babel-cli locally
  • Is it possible to do multiple class imports with ES6/Babel?
  • Why does babel use setProtoTypeOf for inheritance when it already does Object.create(superClass.prototype)?
  • Using webpack with babel and babel-preset-react and babel-preset-es2015
  • 2 Solutions collect form web for “Meteor cannot find re-exported module”

    Which version of node are you testing with? I bet you if you did meteor node and tried the same require('frog-utils') it wouldn’t work, because meteor currently uses node 4.5 (at least in 1.4.X).

    I’m afraid you won’t be able to use ES6 in your npm package without compiling it (also see https://github.com/meteor/meteor/issues/4828). However compiling is not very hard, you can look how I just solved a very similar problem in:
    https://github.com/chfritz/ros_msg_utils/blob/add_babel/package.json

    The trick is to define a script that compiles the code using babel on install.

      ...
      "main": "dist/index.js",
      "scripts": {
        "compile": "babel --presets es2015 index.js -d dist/ && babel --presets es2015 lib -d dist/lib/",
        "preinstall": "npm run compile"
      ...
    

    This seems to have been solved in the latest Meteor release (1.4.2.1), it suddenly began “just working”.