Package can't import NPM module when testing server side

Hello, I hope I can get a bit of help for a testing issue that has been nagging me…

I found a related issue but it is marked as closed so I assume I am missing something…

This is my package.js:

  name: 'sample-test-package',
  version: '0.0.1',
  // Brief, one-line summary of the package.
  summary: '',
  // URL to the Git repository containing the source code for this package.
  git: '',
  // By default, Meteor will default to using for documentation.
  // To avoid submitting documentation, set this field to null.
  documentation: ''

  github: '6.0.1'

Package.onUse(function(api) {
  api.mainModule('sample-test-package.js', 'server');

Package.onTest(function(api) {
  api.mainModule('sample-test-package-tests.js', 'server');

And my test file is just this (my sample-test-package.js is the same):

import github from 'github'

But I get this error when running test with meteor test-packages --driver-package sample-test-package:

W20161101-05:53:53.543(-4)? (STDERR) /home/nico/.meteor/packages/meteor-tool/.
W20161101-05:53:53.544(-4)? (STDERR)                                            throw(ex);
W20161101-05:53:53.544(-4)? (STDERR)                                            ^
W20161101-05:53:53.544(-4)? (STDERR) 
W20161101-05:53:53.544(-4)? (STDERR) Error: Cannot find module './error'
W20161101-05:53:53.544(-4)? (STDERR)     at require (packages/modules-runtime.js:109:19)
W20161101-05:53:53.544(-4)? (STDERR)     at meteorInstall.node_modules.meteor.local-test:sample-test-package.node_modules.github.lib.index.js (/tmp/meteor-test-runzvozob/.meteor/local/build/programs/server/packages/local-test_sample-test-package.js:52:13)
W20161101-05:53:53.545(-4)? (STDERR)     at fileEvaluate (packages/modules-runtime.js:181:9)
W20161101-05:53:53.545(-4)? (STDERR)     at Module.require (packages/modules-runtime.js:106:16)
W20161101-05:53:53.545(-4)? (STDERR)     at Module.Mp.import (/home/nico/.meteor/packages/modules/.0.7.7.pfbopy++os+web.browser+web.cordova/npm/node_modules/reify/lib/runtime.js:70:16)
W20161101-05:53:53.545(-4)? (STDERR)     at meteorInstall.node_modules.meteor.local-test:sample-test-package.sample-test-package-tests.js (packages/local-test:sample-test-package/sample-test-package-tests.js:1:20)
W20161101-05:53:53.546(-4)? (STDERR)     at fileEvaluate (packages/modules-runtime.js:181:9)
W20161101-05:53:53.547(-4)? (STDERR)     at require (packages/modules-runtime.js:106:16)
W20161101-05:53:53.547(-4)? (STDERR)     at /tmp/meteor-test-runzvozob/.meteor/local/build/programs/server/packages/local-test_sample-test-package.js:889:15
W20161101-05:53:53.547(-4)? (STDERR)     at /tmp/meteor-test-runzvozob/.meteor/local/build/programs/server/packages/local-test_sample-test-package.js:895:3
=> Exited with code: 1

I looked in the built file and the ./error module is being imported from inside of the github module:

//                                                                                                                    //
// node_modules/meteor/local-test:sample-test-package/node_modules/github/lib/index.js                                //
//                                                                                                                    //
"use strict";

var error = require("./error");

If I remove the import line then it works fine. Also in production it works fine. And if I change the “server” to “client” in package.js it seems to work fine too, though I don’t understand why as the built file seem similar, but obviously I don’t know enough about the Meteor build process :slight_smile:

I would appreciate any help.

Got a similar issue while testing (different npm package). I don’t know either what is going on. Out of curiosity are you on 1.4.2 ? Try downgrading to

Yes this is on 1.4.2… I will try on and report back!

I ran it using --release and it seemed to work. Maybe a 1.4.2 bug?


Yeah that looks like a match! Thank you!

Works beautifully on, thanks Meteor!

I faced the same problem as well. but the guys from broadaxis helped me and now everything works like a charm.

Also I guess the official guide will help you as well.