Eventually, the Node ecosystem has to move to ESM #3689
Replies: 9 comments 2 replies
-
Everything is in a state of flux. Only those who are adaptable can survive. We love AdonisJS. 💖💖 |
Beta Was this translation helpful? Give feedback.
-
I think it's a good idea to move with the trend instead of being left behind. AdonisJS ❤️ |
Beta Was this translation helpful? Give feedback.
-
Why not, the sooner the better. |
Beta Was this translation helpful? Give feedback.
-
This is an easy 👍 vote for me because I am not doing the work 🤣. I believe you are quite right in that this is the direction active node packages should move as it is newer, broader (works in browsers!), and actually part of the ECMAScript standard. That said, there is a trade-off: do it earlier and enjoy the benefits vs. wait longer and enjoy a smoother transition thanks to the work of others who have gone before (and maybe written a few codemods, blog posts, etc.). FWIW, you can mimic the functionality of import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename); You can even get |
Beta Was this translation helpful? Give feedback.
-
My vote would have been No but It seems like it's inevitable. |
Beta Was this translation helpful? Give feedback.
-
Would it be possible to make Adonis compatible with Deno at the same time? I've seen other node projects (like Nuxt 3) become "runtime agnostic" to where they can run in Deno, Node, or the Browser and I think that's another part of the Future Proofing question |
Beta Was this translation helpful? Give feedback.
-
What is the NodeJS recommendation about If Adonis move forward with the language, that in my opinion it should, it should explain/recommend the path forward on how to implement those breaking changes. // before
path.join(__dirname, ...)
// after
... |
Beta Was this translation helpful? Give feedback.
-
if adonis 5 had a sable version then there is no problem. |
Beta Was this translation helpful? Give feedback.
-
if i can suggest, i think the example: import View from '@ioc:Adonis/Core/View' => const View = import.meta.container('@ioc:Adonis/Core/View') |
Beta Was this translation helpful? Give feedback.
-
Node.js has supported ES modules as a first-class citizen for a while now. As a result, you can use them without any transpiler or bundler.
However, moving from CommonJS
(require('some-package'))
to ESMimport 'some-package'
is a breaking change at many levels. I will not go in-depth about those breaking changes right now but leave some pointers that you help you make your decision for the vote.All relative imports needs a
.js
extension.Directory imports with
index.js
no longer workGlobals like
__filename
,__dirname
, andrequire
are not availableAs the title says, you cannot use
__filename
,__dirname
globals inside your code, and neither use methods likeresolve
from therequire
object.JSON imports needs assertion types
You cannot import a JSON file similar to a JavaScript file (earlier, it was possible). Instead, you need to use the following syntax.
import pkg from './package.json' assert { type: 'json' };
Can we live without migrating to ESM?
Well, not in the longer run. A lot of packages are already moving to ESM only. For example, a prolific Node.js developer Sindresorhus has decided to move all his packages to ESM, and therefore, the core of AdonisJS + your application will not be able to use his packages (and any other ESM only package).
Therefore, the change is inevitable, and sooner or later, we will have to migrate.
Can migration be automated?
To a certain level, yes. I am playing with codemods, which can rewrite some of the imports automatically for you. However, not everything can be automated and will require manual effort (at least for verification)
345 votes ·
Beta Was this translation helpful? Give feedback.
All reactions