简体   繁体   中英

Ember-cli how to add FileSaverjs and Blobjs

I looked at this and that link. I bower installed file-saver and Blob. I am having a similar problem with both components so I will just talk about one.

When I do import FileSaver from 'file-saver';

I get the following error.

Error while processing route: some.route Could not find module `file-saver` imported from `client/pods/some/folder/controller` Error: Could not find module `file-saver` imported from `client/pods/some/folder/controller`

I know the I have file-save because it is in my bower_components folder.

And right about the line that is giving me trouble is the following line.

import Ember from 'ember';

that package is about the file-saver package in my bower_components folder. And the app seems to find that package.

Bower assets have to be imported in Brocfile.js , see http://www.ember-cli.com/#managing-dependencies

In my project, filesaver is located at bower_components/FileSaver.js/FileSaver.js , so I have the following line in my Brocfile.js :

app.import('bower_components/FileSaver.js/FileSaver.js');

This makes it available as a global on window.saveAs , no need to use an import statement in the file you use it in.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM