Subscribe on changes!

Remove CJS build for @vue/compat

avatar
Sep 5th 2022

What problem does this feature solve?

@vue/compat depends on estree-walker, which doesn't support CJS build: https://stackblitz.com/edit/node-apcmcb?file=index.js

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in /home/projects/node-apcmcb/node_modules/estree-walker/package.json

This causes issues in Vitest, for example (#1978), or any tools that imports it without preprocessing.

What does the proposed API look like?

I propose removing CJS build altogether, but keep index.js with an if statement (I assume it's used for more old tools that don't understand "exports" field.) If it is meant to be used with estree-walker@2, we should have it for compatibility with Jest. (it's not specified in package.json)

I would also recommend adding "exports" field with compatible Node ESM build (meaning, type: "module" or .mjs extension, docs)

{
  "exports": {
    ".": {
      "development": "./index.dev.mjs"
      "import": "./index.mjs",
      "require": "./index.js"
    },
  }
}
// index.dev.mjs
export * from './dist/vue.esm.mjs'
// index.mjs
export * from './dist/vue.esm.prod.mjs'
avatar
Sep 28th 2022

The root cause is that @vue/compat did not list its own dependencies, so it was resolving to a hoisted & newer version of estree-walker that doesn't have CJS build.

avatar
Sep 28th 2022

@yyx990803 @sheremet-va I bumped VTU to Vue v3.2.40 and tried the latest vitest release, and the issue is still there https://github.com/vuejs/test-utils/actions/runs/3141055322/jobs/5103078070