Import external javascript : Cant resolve ...

1
Hi ! I’m trying to use an external javascript library in my project, but I can’t figure out how to properly import it. I followed the procedure described here: “https://docs.mendix.com/howto8/extensibility/best-practices-javascript-actions#2-2-6-using-external-dependencies-in-the-browser”. But obvioulsy my import is not ok… Does anybody have an example project somewhere? Thx !
asked
2 answers
1

I guess you did steps 1, 2, and 3 of

2.2.6 Using External Dependencies in the Browser

Loading and bundling external libraries are not currently supported. Embedding library code and CSS inside the JavaScript is not ideal. Adding the library JavaScript file and CSS into the theme folder and referencing them in the index.html and the components.json is recommended.

Below is an example of using an external dependency based on pdf-lib:

1)    Open Command Prompt and navigate to the right folder using cd --your-project-folder--/javascriptsource/--ModuleName--/actions.
2)    Run npm install pdf-lib.
3)    In the JavaScript action, use the following code to import the library:

    // This file was generated by Mendix Studio Pro.
    //
    // WARNING: Only the following code will be retained when actions are regenerated:
    // - the import list
    // - the code between BEGIN USER CODE and END USER CODE
    // - the code between BEGIN EXTRA CODE and END EXTRA CODE
    // Other code you write will be lost the next time you deploy the project.
    import { Big } from "big.js";
    import { PDFDocument } from "pdf-lib"

    // BEGIN EXTRA CODE

If so, can you first try this with the pdf-lib, see if that works. Just to check if the problem might be with the javascript library that you are trying to load.

answered
0

Have you called resolve on the Promise in the JavaScript action?

answered