lovasoa / base45-ts

Base45 (for QR and Aztec barcode alphanumeric mode) library for Javascript/JS/node
1 stars 0 forks source link

How do I use this library? #1

Open panzi opened 3 years ago

panzi commented 3 years ago

If I try to import { decode as b45decode } from 'base45-ts'; I just get this when I try to run the compiled program:

node:internal/modules/cjs/loader:1125
      throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
      ^

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /home/panzi/job/git/ehcjs/node_modules/base45-ts/lib/base45.js
require() of ES modules is not supported.
require() of /home/panzi/job/git/ehcjs/node_modules/base45-ts/lib/base45.js from /home/panzi/job/git/ehcjs/dist/index.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename base45.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /home/panzi/job/git/ehcjs/node_modules/base45-ts/package.json.

    at new NodeError (node:internal/errors:363:5)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1125:13)
    at Module.load (node:internal/modules/cjs/loader:988:32)
    at Function.Module._load (node:internal/modules/cjs/loader:828:14)
    at Module.require (node:internal/modules/cjs/loader:1012:19)
    at require (node:internal/modules/cjs/helpers:93:18)
    at Object.<anonymous> (/home/panzi/job/git/ehcjs/dist/index.js:8:21)
    at Module._compile (node:internal/modules/cjs/loader:1108:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
    at Module.load (node:internal/modules/cjs/loader:988:32) {
  code: 'ERR_REQUIRE_ESM'
}