简体   繁体   中英

How to import npm module in JavaScript stimulus

I want to use imageToZ64() from zpl-image module

I have installed it using: npm install zpl-image

and then I import it: import './../../../node_modules/zpl-image';

but when I use the fucntion like this let res = imageToZ64(canvas); i'm getting : Uncaught (in promise) ReferenceError: imageToZ64 is not defined

I tried to import it like this: import { imageToZ64 } from './../../../node_modules/zpl-image/zpl-image';

but the problem is this function uses other functions from pako.js which is another js file in the zpl-image. my question is how to import the module in a way that I can be able to access all the functions?

I highly recommend you read the README here : zpl-image repo GitHub

In order to use this with Node.js :

const imageToZ64 = require("zpl-image").imageToZ64;

Or :

const { imageToZ64, rgbaToZ64 } = require("zpl-image");

If you are trying to use it in the browser read generic browser usage since you already installed it via npm there is a demo file in node_modules/zpl-image/zpl-image.html ,you can open it in the browser, read its content, and understand how the code works which is the purpose of the demo file.

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