Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing an es6 module that may not exist

Tags:

ember-cli

Just say I create an addon that is shared with other users and I need to import ember-data.

import DS from 'ember-data';

How can I import this given it might not exist in the client code. Basically I need a condition to check if ember-data is available, if so import it and do something, else don't do it.

if(ember data exists) {
  //do something
}
like image 499
jax Avatar asked Jan 10 '15 05:01

jax


1 Answers

I have the same question for general es6 usage, but assuming you're using ember-cli you can look at the require._eak_seen object so your code could potentially look something like:

if(require._eak_seen['ember-data']){
  //your code
}
like image 155
JackCA Avatar answered Oct 22 '22 12:10

JackCA