pattern-matching-ts icon indicating copy to clipboard operation
pattern-matching-ts copied to clipboard

require() of ES modules is not supported

Open craigmiller160 opened this issue 3 years ago • 0 comments

I'm working on a NodeJS application written in TypeScript. All my source TS files are being compiled and outputted with the CommonJS require/module.exports format. I am trying to start using this library, but I get this error:

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /home/me/Development/Applications/craig-build/node_modules/pattern-matching-ts/lib/match.js
require() of ES modules is not supported.
require() of /home/me/Development/Applications/craig-build/node_modules/pattern-matching-ts/lib/match.js from /home/me/Development/Applications/me-build/src/temp.ts 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 match.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /home/me/Development/Applications/me-build/node_modules/pattern-matching-ts/package.json.

This appears to stem from the use of "type": "module" in the package.json file. Is it possible to correct this so that this library will be compatible with NodeJS applications?

Edit: On further review, it appears that the code is entirely in ES Module format, and offers no CommonJS option. Is there anything that can be done about this?

craigmiller160 avatar Dec 20 '21 18:12 craigmiller160