Esm: What's the recommended usage for transitioning to mjs?

Created on 24 Aug 2017  路  1Comment  路  Source: standard-things/esm

How should we use this as a helper for transitioning to mjs? Such as:

package.json:

{
  name: 'some-module',
  main: 'main.js',
  module: 'main.mjs'
}

main.js:

require = require("@std/esm")(module)
module.exports = require("./main.mjs").default

main.mjs:

export default // ... real module code.

So that the majority in npm would be written in mjs at last.

Since module field in package.json is still a proposal, is there another recommended way for doing this?

question

Most helpful comment

Hi @amio!

The module field doesn't really factor into things at the moment.
The suggested usage for the current released versions is to use a main cjs file to bootstrap loading esm files. If the module field doesn't become a thing when 2020 rolls around, and you'd like to drop @std/esm, then you'd simply swap the main field to main.mjs.

>All comments

Hi @amio!

The module field doesn't really factor into things at the moment.
The suggested usage for the current released versions is to use a main cjs file to bootstrap loading esm files. If the module field doesn't become a thing when 2020 rolls around, and you'd like to drop @std/esm, then you'd simply swap the main field to main.mjs.

Was this page helpful?
0 / 5 - 0 ratings