user15607380
user15607380

Reputation:

using requirejs to load npm packages

i want to use this code in run in html, how could i use require.js to do this

const monerojs = require("monero-javascript");

the following doesnt work i get "Script error for "monero-javascript""

requirejs(["monero-javascript"], function(monerojs) {

    main();
    async function main() {

    let walletKeys = await monerojs.createWalletKeys({networkType: "stagenet", language: "English"});
    }
 });

Upvotes: 0

Views: 1268

Answers (1)

Quentin
Quentin

Reputation: 944320

Require.JS is for loading AMD modules.

Node.js modules are either ECMAScript modules (which use import and export) or CommonJS modules (which use require and module.exports).

Even though both AMD and CommonJS modules use a function named require they are, in general, not compatible. (It is possible to write a module so that it meets the requirements of both AMD and CommonJS but this isn't too common).

If you want to use Node.js modules in the browser then use a bundler like Webpack or Parcel (but note that they cannot provide APIs that are specific to Node.js, such as the fs module for reading and writing to and from the file system).

Upvotes: 2

Related Questions