standard-things / esm

Tomorrow's ECMAScript modules today!
Other
5.27k stars 147 forks source link

Does this support the "exports" property in package.json? #863

Open trusktr opened 4 years ago

trusktr commented 4 years ago

I am using "exports" in new project's package.json that I run in Node.js v13.2+ and it works great.

(Note, specifically Node v13.2+ because 13.2 introduced a feature where mapping a folder in exports causes it to behave exactly like the desired functionality of mainDir that is expressed in https://github.com/nodejs/node/issues/14970).

In particular the feature that I'm wondering about is, if a path is mapped to another path using exports, then the consumer of the package can import anything from that mapped folder and subfolders. Prior to Node 13.2 mapping a folder would cause any of its sub-folders to be unavailable for import.

For example, my exports field is like this normally:

    "exports": {
        ".": "./dist/index.js",
        "./": "./dist/"
    },

And this means a user can:

// causes Node to load the-package/dist/Foo.js:
import {Foo} from 'the-package/Foo.js'

// causes Node to load the-package/dist/index.js:
import {blah} from 'the-package'

Does esm support this same functionality? I'm looking for something to fallback to until Electron is released with Node 14. They are on Node 12 right now, and only ship with LTS Node.

damianobarbati commented 4 years ago

OT

@trusktr are you using named imports in production with node 13 today? I'm asking because most of libs do not provide exports (i.e: lodash-es) thus named import do not work with them, and this is preventing me from upgrading to v13+esm. Did you manage to work it around?