Quantcast
Viewing all articles
Browse latest Browse all 4829

Dynamic import a file with ember-auto-import that is not located in node_modules folder

@franip wrote:

Hi there!

I’m trying to dynamic import a file with ember-auto-import that is not located in node_modules folder and I having problems.

I’m using pdfmake to create PDF files in the client and when I use ember-auto-import to load dynamically the library and the fonts it works perfectly fine:

@dropTask
*createPDF() {
    let pdfMake = yield import('pdfmake/build/pdfmake.min').then(module => module.default);
    let pdfFonts = yield import('pdfmake/build/vfs_fonts').then(module => module.default);
    pdfMake.vfs = pdfFonts.pdfMake.vfs;
    ...
}

With this library you can use your own custom fonts so I have a file with the fonts definition stored in my project but when I try to import it the same way I have a runtime error: Error: Could not find module '_eai_dyn_myapp/pdf/my-custom-fonts' imported from '(require)'

The file is stored in a folder named pdf inside my app folder:

myapp
|-- app
    |-- pdf
        |-- my-custom-fonts.js

This is how I import it:

@dropTask
*createPDF() {
    let pdfMake = yield import('pdfmake/build/pdfmake.min').then(module => module.default);
    // first option
    let pdfFonts = yield import('myapp/pdf/my-custom-fonts').then(module => module.default);
    // second option (a relative path)
    let pdfFonts = yield import('../../pdf/my-custom-fonts').then(module => module.default);
    pdfMake.vfs = pdfFonts.pdfMake.vfs;
    ...
}

With both options I get the mentioned runtime error. How can I import the file?

Thank you.

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4829

Trending Articles