Correct way to load module from node_modules


#1

I’m slightly confused as to the correct way to load a module from node_modules in one of my controllers. I’ve added aws-sdk using yarn which has installed it in node_modules. I’m using Ember 3.0 The documentation for managing dependencies here: https://guides.emberjs.com/v3.0.0/addons-and-dependencies/managing-dependencies/

Talks at great lengths about bower. However from my understanding Bowers actually being phased out?

I’ve tried simply import {AWS} from 'aws-sdk'; or various versions of import {AWS} from 'node_modules/aws-sdk'; that results in ‘could not find module’ errors.

Having googled a lot I’ve found various different methods that might work

  • Ember-Browserify
  • Creating a vendor shim? (I don’t really understand why this would be necessary if what I’m importing is already in a module format)
  • Use app.import in ember-cli-build.js - but would this then import it globally?

I’m not certain on is what is the current way of doing this.

This seems like a very basic fundamental thing to want to do - I’m curious why the documentation seems to not be very helpful on this front - is it awaiting updating? - am I missing something?, or looking at this in the wrong way?.

Thanks, Chris.


#2

aws-sdk supports Browserify so you could use that. You can also create a shim add-on that finds the bower version and import it like this.

Don’t know what is the correct way. I like the shim more because it is easy to create add-on’s with your shim add-on that don’t depend on Browserify.