developit / htm

Hyperscript Tagged Markup: JSX alternative using standard tagged templates, with compiler support.
Apache License 2.0
8.7k stars 170 forks source link

[ERR_UNSUPPORTED_DIR_IMPORT]: Directory import 'project/node_modules/htm/preact' is not supported resolving ES modules imported from #191

Closed TimDaub closed 3 years ago

TimDaub commented 3 years ago

👋🏼

node -v
v14.15.4

And my project is using ESM import { html } from "htm/preact";. When I try to run this, I get the following error:

Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '/Users/user/Projects/project/node_modules/htm/preact' is not supported resolving ES modules impor
ted from /Users/user/Projects/project/test/build_test.mjs
  Did you mean to import htm/preact/index.js?

I know that it I can resolve it myself by passing --experimental-specifier-resolution=node to node, but I'd rather not do that.

Did you mean to import htm/preact/index.js?

This works as a way of resolve it too. But is it safe for the future?

developit commented 3 years ago

Hiya @TimDaub - looks like we need to add Package Exports to this module.

developit commented 3 years ago

related: #181

rschristian commented 3 years ago

Late to the party here, but looks like package exports were added just about a year ago now. Anything planned before a release, as I imagine exports will need a major?

Don't mean to pester, but with Node 10 being officially EOL and "type": "module" being supported from v12+, I imagine we're going to see an uptick in ESM usage here. I'm starting to switch some of my things over and I've seen a few authors are switching over to ESM-only, so I imagine more people will start running into this shortly.

developit commented 3 years ago

This should be fixed as of version 3.1.0.