stefano-regosa-deel/pattern-matching-ts

require() of ES modules is not supported

Opened this issue · 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?