Skip to content

Bug: Node doesn't resolve ESM correctly #1483

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

Closed
sheremet-va opened this issue May 8, 2022 · 0 comments · Fixed by #1484
Closed

Bug: Node doesn't resolve ESM correctly #1483

sheremet-va opened this issue May 8, 2022 · 0 comments · Fixed by #1484
Labels
bug Something isn't working

Comments

@sheremet-va
Copy link
Contributor

sheremet-va commented May 8, 2022

Describe the bug

@vue/test-utils provides module field, that is resolved by bundlers, but if I import library with native node (or vitest, that used native node module resolution), then imported module will be in cjs (/dist/vue-test-utils.cjs). Other issue is that all files have the same extension (js), which is not supported by Node (For reference: https://github.com/sheremet-va/dual-packaging).

This leads to @vue/test-utils importing cjs version of Vue in Vitest, which fails the tests (with --no-threads), because it was already required() when defining plugin.

To Reproduce

import { mount } from '@vue/test-utils'
// leads to cjs.js

Expected behavior

import { mount } from '@vue/test-utils'
// leads to esm.mjs

@vue/test-utils needs an exports field, so Node will correctly resolve paths:

  "exports": {
    ".": {
      "types": "./dist/index.d.ts",
      "import": "./dist/vue-test-utils.esm-bundler.mjs",
      "browser": "./dist/vue-test-utils.browser.js",
      "require": "./dist/vue-test-utils.cjs.js",
      "default": "./dist/vue-test-utils.cjs.js"
    }
  },

And mjs extension on esm files (will require twicking bundling process).

Related information:

  • @vue/test-utils version: any
  • Vue version: not relevant
  • node version: not relevant
  • npm (or yarn) version: not relevant

Additional context

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant