gildas-lormeau / zip.js

JavaScript library to zip and unzip files supporting multi-core compression, compression streams, zip64, split files and encryption.
https://gildas-lormeau.github.io/zip.js
BSD 3-Clause "New" or "Revised" License
3.38k stars 510 forks source link

require() of ES modules is not supported. #362

Closed ivanzwb closed 1 year ago

ivanzwb commented 2 years ago

When import zip.js in Typescript project.

import { ZipReader, ZipWriter } from '@zip.js/zip.js';

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: \node_modules\@zip.js\zip.js\index.js require() of ES modules is not supported.

Can we support the commonjs module as well?

gildas-lormeau commented 2 years ago

Add "type": "module" in your package.json file. zip.js was not designed for Node.js. It just turned out that as time passed, Node.js became more and more compatible with zip.js. That is why it does not offer CommonJS support.

peaceps commented 1 year ago

When import zip.js in Typescript project.

import { ZipReader, ZipWriter } from '@zip.js/zip.js';

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: [node_modules@zip.js](mailto:node_modules@zip.js)\zip.js\index.js require() of ES modules is not supported.

Can we support the commonjs module as well?

We can use tsimportlib to do async import for commonjs

gildas-lormeau commented 1 year ago

I'm moving this issue to the Discussions tab because CommonJS support in zip.js is not planned but we can discuss it if needed.