user1814277
user1814277

Reputation: 304

Ember addon: Could not find module from within component

In a new ember 3.28 addon project:

npm install chart.js --save
ember g component-class chart

Insert <Chart /> into application.hbs on dummy app and in addons/component/chart.js, add this

import Chart from 'chart.js/auto';

Running app gives:

Uncaught Error: Could not find module `chart.js/auto` imported from `chartjs-test/components/chart`

Yet if the import Chart goes into the application.js route in the dummy app instead, it works. How can you import this module correctly from within an addon component?

Update: Same issue with other installed packages eg. import chroma from "chroma";

Upvotes: 0

Views: 1421

Answers (1)

user1814277
user1814277

Reputation: 304

Turns out you need to add the same import statement into app/component/chart.js:

UPDATE: The above isn't the proper way and causes issues when using the addon elsewhere. The real solution is to move ember-auto-import to dependencies from devDependencies in package.json of the addon

Upvotes: 2

Related Questions