Meteor cannot find re-exported module

I am writing a Meteor application using ES6, and I have several subcomponents that I want to save as separate npm packages. I have a library called frog-utils that is common to all packages and contains common helper functions.

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

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 a regular 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 write in ES6 using Babel to create output files that are exposed by the module, and 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; } }); 

(ES6 string is used here)

 export {default as color_range} from './color_range' 
+7
javascript babeljs meteor node-modules
source share
2 answers

What version of node are you testing with? I bet if you made a meteor node and tried the same require('frog-utils') , that would not work, because the meteorite currently uses node 4.5 (at least 1.4.X).

I am afraid that you will not be able to use ES6 in your npm package without compiling it (see also https://github.com/meteor/meteor/issues/4828 ). However, compiling is not very complicated, you can see how simple I am 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 with babel during installation.

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

This seems to have been resolved in the latest release of Meteor (1.4.2.1), it suddenly started to "just work."

+1
source share

All Articles