kristian / minify-xml

Fast XML minifier / compressor / uglifier with a command-line
Other
15 stars 5 forks source link

Err Require ESM #21

Closed davidbesteltunts closed 1 year ago

davidbesteltunts commented 1 year ago

Hello, I'm trying to use the library but I'm getting this error:

var import_minify_xml = __toESM(require("minify-xml"));
Error [ERR_REQUIRE_ESM]: require() of ES Module

My project is in Typescript, maybe it's some incorrect configuration on my part, but I'd like to ask if you've ever experienced this error?

I'm importing the library this way: import minifyXML from 'minify-xml';

In dist it looks like this: var import_minify_xml = __toESM(require("minify-xml"))

kristian commented 1 year ago

I am not really familiar with typescript, but minify-xml, like next to all current NodeJS libraries is now using the ES module format, since its 4.0.0 release. The last release supporting the old CommonJS module format / require is 3.5.0. I don't know how to instruct TypeScript NOT to transpile an import into a require, but I would not consider this one a bug of minify-xml.

davidbesteltunts commented 1 year ago

thanks for the reply, I'll try other alternatives.

kristian commented 1 year ago

@davidbesteltunts you are welcome. :) As said, you can also pin to 3.5.0, which still supports require and has no further changes adapted yet. In order to consume ES modules in typescript see [1].

[1] https://www.typescriptlang.org/docs/handbook/modules/reference.html#node16-nodenext