esm icon indicating copy to clipboard operation
esm copied to clipboard

std/esm vs native esm in V14

Open dkebler opened this issue 4 years ago • 2 comments

I'm hoping to get some help here from the experts although it's technically not a std/esm issue. I am attempting move away from std/esm and use the "native" esm in V14.

The issue I am having is that unlike std/esm the native version is breaking the named imports (from I assume commonjs module exports) that worked fine with std/esm.

Take for example https://github.com/sindresorhus/make-dir/blob/978bee9186bf0c41640ed21567921daf8c303225/index.js#L106

I have in my package the import import { sync as mkdir } from 'make-dir' which works fine in std/esm. But using native it says it can't find the named export sync.

Am I stuck here? Do I need to stay with std/esm? (but it looks like the project is over now) I can't/shouldn't go through my entire code base accommodating cjs modules with

import mk from 'make-dir'
const mkdir = mk.sync

Also if I add to any package.json "type":"module" and run with std/esm it throws errors so it looks like I can't mix these.

Anyway was under the assumption that the native was going to be a drop in replacement for using std/esm. Apparently not :(.

I made a stack overflow post of this. Maybe best to reply there? https://stackoverflow.com/questions/62088912/std-esm-vs-native-esm-in-node-v14-cant-find-named-import-from-cjs-modules

dkebler avatar May 29 '20 14:05 dkebler

made an issue at nodejs https://github.com/nodejs/node/issues/33795 and also a repo to demonstrate https://github.com/dkebler/core-esm-named-import-error

dkebler avatar Jun 08 '20 17:06 dkebler

That was kinda of the danger of using esm before the commonjs interop was officially defined by node. And unfortunately until packages update to have real named exports, you will have to update your imports like you've done above.

jsg2021 avatar Jul 24 '20 09:07 jsg2021