Any plan to support node ESM?
See original GitHub issueIām submitting aā¦
- Bug report
- Feature request
- Question
Current behavior
The default generated migrations are all CJS files and can not be used in a ESM node project (type="module"
in package.json).
It seems that node-db-migrate hardcoded the .js
suffix. If I change the migration files extension to .cjs
, it canāt recognize them at all.
Expected behavior
Provide an option to generate ESM migration code or recognize .cjs
migration files.
Environment
db-migrate version: 1.0.0-beat.14
plugins with versions: none
db-migrate driver with versions: sqlite3 0.4.0
Additional information:
- Node version: 15.5.0
- Platform: Mac
Issue Analytics
- State:
- Created 3 years ago
- Comments:13 (12 by maintainers)
Top Results From Across the Web
Using ECMAScript modules (ESM) with Node.js
In this article, we'll explore how far this journey of supporting both worlds has come in the Node.js universe. We'll create a couple...
Read more >What does it take to support Node.js ESM? ā The Guild
To add support ESM for Node.js, you have two alternatives: build your library into ESM Compatible modules with the extension .mjs , and...
Read more >Question: Plans for Node.js ESM Module Support? #1946
Has there been any talk about how the Node side of the project is going to address to coming ESM/ES6 module migration that...
Read more >ECMAScript modules | Node.js v19.3.0 Documentation
Node.js fully supports ECMAScript modules as they are currently specified ... CommonJS modules consist of a module.exports object which can be of any...
Read more >Announcing core Node.js support for ECMAScript modules
Node.js 13.2.0 ships support for ECMAScript modules, known for their import and export statements. This support was previously behindĀ ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Adding an unused
import()
does not throw an error in any LTS versions of NodeJS, starting with Node 10. Does db-migrate support node@9? Thatās the latest version of Node that throws an error when it sees a dynamicimport()
in a file. I see that the package.json says that node >= 8 is supported on the master branch for version 1.0.0-beta.14 - if thatās true then yes it would be a breaking change.The main benefit I see is not throwing errors when users have set
"type": "module"
in their package.json. āDonāt use ES Modulesā is an arbitrary and unnecessary restriction to place on users.Alternative solution
Another solution would be to generate migration js files with the
.cjs
extension when inside of a package that has"type": "module"
, and then have db-migrate look for either.js
or.cjs
when callingrequire()
. This solution would work in Node 8 as far as I know, so it could be a good solution if backwards compatibility with Node 8 is needed.ššæ Iāve created #724 which addresses this for the 1.x beta versions.