question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if youā€™re still stuck at the end, weā€™re happy to hop on a call to see how we can help out.

Any plan to support node ESM?

See original GitHub issue

Iā€™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:closed
  • Created 3 years ago
  • Comments:13 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
joeldenningcommented, Feb 28, 2021

Just introducing the word import anywhere in the code will break it for thousands of users

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 dynamic import() 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.

wouldnā€™t mind to introduce it if it brings any benefit

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 calling require(). 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.

0reactions
joeldenningcommented, Mar 1, 2021

šŸ‘šŸæ Iā€™ve created #724 which addresses this for the 1.x beta versions.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found