masumsoft / express-cassandra

Cassandra ORM/ODM/OGM for NodeJS with support for Apache Cassandra, ScyllaDB, Datastax Enterprise, Elassandra & JanusGraph.
http://express-cassandra.readthedocs.io
GNU Lesser General Public License v3.0
228 stars 67 forks source link

fix: support .cjs extension for use in esm module #253

Closed face closed 1 year ago

face commented 1 year ago

If the model extension is .js and a esm module uses express-cassandra you get the following error in node v14.19.3:

require() of FooModel.js from /home/face/proj/test/test-api/node_modules/express-cassandra/lib/expressCassandra.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 CommentsModel.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /home/face/proj/test/test-api/package.json.

This adds .cjs to the file filter so express-cassandra can then use require() on your models using the .cjs file extension.