Skip to content

Bug: Node doesn't resolve ESM correctly #1483

Closed
@sheremet-va

Description

@sheremet-va

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions