ember-browserify: npm-installed dependencies are not available during tests

As an example:

npm install --save-dev ember-browserify
npm install --save-dev moment

From app/router.js

import moment from 'npm:moment';

works just fine, but in any test module (e.g. tests/adapters/application.js), the same line provokes an error:

Uncaught Error: Could not find module npm:moment

Environment:

  • ember-cli: 0.1.5
  • ember: 1.8.1

Tests using ember-cli-mocha.

About this issue

  • Original URL
  • State: open
  • Created 9 years ago
  • Reactions: 1
  • Comments: 22 (14 by maintainers)

Most upvoted comments

any updates on this?

@oliverwilkie You can manually exclude the package from production builds

// config/environment.js
module.exports = function(environment) {
  var ENV = {
    environment: environment,
    baseURL: '/',
    locationType: 'auto',

    // ...

    browserify: {
      // your browserify options if you have any
      ignores: [ ]
    },
  };

  if (environment === 'production') {
    ENV.browserify.ignores.push('my-cool-npm-package');
  }

  return ENV;
};

The ember-cli folks are working on a big internal refactor that will make ember-browserify-like functionality first-class.