0

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.

Community
  • 1
  • 1
artych
  • 3,669
  • 1
  • 17
  • 30

1 Answers1

1

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';

Community
  • 1
  • 1
jmurphyau
  • 2,309
  • 13
  • 11
  • Yeah, I know this approach, but something goes wrong with `getstream` library. On `ember server` error is raised: Cannot find module 'browser-request' from '``/node_modules/getstream/src' Error: Cannot find module 'browser-request' from '``/node_modules/getstream/src' at ``/node_modules/ember-browserify/node_modules/browserify/node_modules/resolve/lib/async.js:46:17 – artych Jun 06 '15 at 09:43
  • I was able to fix it. Thanks, jmurphyau! – artych Jun 06 '15 at 12:23
  • I find it works after adding `browser-request` to dependencies. [Commit](https://github.com/artych/stream-js/commit/7aa0be696c4926eeb1c06d83f17ad6723a5bd4d0) – artych Jun 06 '15 at 15:11