Search code examples
ember-cli

Create shim for ember-cli


I am trying to create shim for getstream library for ember-cli as @jmurphyau answered here.

I bower install getstream, then create file

vendor/shims/getstream.js

(function() { 
  /* globals define, getstream */

  function getstreamModule() { 

    'use strict';

    return getstream; // <-- got error here
  }

  define('getstream', [], getstreamModule);

})();

and add lines to Brocfile.js

app.import('bower_components/getstream/dist/js_min/getstream.js');
app.import('vendor/shims/getstream.js', {
  exports: {
   'getstream': [ 'default' ]
  }
});

and try to import Stream from 'getstream'; in route.

Got Uncaught ReferenceError: getstream is not defined in getstream.js

What's going wrong and how it could be fixed? Thanks for answers.


Solution

  • Have you tried using ember-browsify?

    That library doesn't look like it exposes a global variable called getstream which is why your getting that error.

    It does however look like it supports CommonJS module syntax so ember-browserify should work.

    1. Install ember-browserify

      ember install ember-browserify

    2. Install the CommonJS library as an NPM package

      npm install --save-dev getstream

    3. Use the NPM package with regular import syntax

      import getstream from 'npm:getstream';