Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node.js ESM export support #71

Closed
pi0 opened this issue Jul 15, 2021 · 1 comment
Closed

Node.js ESM export support #71

pi0 opened this issue Jul 15, 2021 · 1 comment

Comments

@pi0
Copy link

pi0 commented Jul 15, 2021

Hi :) Trying vue-demi (as a dependency of vue-global-api) on latest nuxt3 version, production build fails since there is no import matcher. (and currently node condition is set to cjs)

Could not resolve import "vue-demi" in ..../node_modules/vue-global-api/onActivated.mjs using exports defined in ..../node_modules/vue-demi/package.json

It can be fixed by adding import field to package.json: (should be ideally esm build)

  "exports": {
    ".": {
      "require": "./lib/index.cjs.js",
++   "import": "./lib/index.cjs.js",
      "node": "./lib/index.cjs.js",
      "browser": "./lib/index.esm.js"
    },
    "./*": "./*"
  },
  • Note: I think it would be much better if you tend to use explicit .mjs and .cjs extensions so that tooling can infer module type.
  • Note: SSR vs Node: node condition can be added to niro resolver but since there are also non Node.js SSR environments (like Cloudflare workers) we would need import only support
@antfu antfu closed this as completed in 8c411b0 Jul 15, 2021
@dragomirweb
Copy link

image
your fix worked

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants