vue-demi icon indicating copy to clipboard operation
vue-demi copied to clipboard

TypeScript got incorrect vue version with pnpm workspace

Open SwingCosmic opened this issue 1 year ago • 1 comments

A workspace project with Vue CLI 5, default vue verison is vue2.7.

Run build:3 succeeded, run build:2 got compiler error TS7006. yarn workspace can pass build, but VSCode still shows errors.

pnpm: 8.6.2 nodejs: 16.20

  • project structure
-- packages
     |-- a
     |-- b 
  • a package.json
{
  "scripts": {
    "build:2": "vue-demi-switch 2.7 && pnpm run build",
    "build:3": "vue-demi-switch 3 vue3 && pnpm run build",
    "build": "vue-cli-service build"
  },
  "devDependencies": {
    // ... other dependencies
    "vue": "^2.7.16",
    "vue-tsc": "^1.8.25",
    "vue3": "npm:vue@^3.2.13",
    "vue-demi": "^0.14.6"
  }
  // ...
}

  • a src/index.ts
import { Plugin } from "vue-demi";
export default {
  install(app, ...options) {
    // do something
  },
} as Plugin;
  • b package.json
{
  "scripts": {
    "build": "vue-cli-service build"
  },
  "devDependencies": {
    // ... other dependencies
    "vue": "^3.2.13",
    "vue-demi": "^0.14.6",
    "a": "*"
  }
  // ...
}

  • output
 error  in src/index.ts:3:11

TS7006: Parameter 'app' implicitly has an 'any' type.
    15 |
    16 | export default {
  > 17 |   install(app, ...options) {
       |           ^^^

And tsc says that vue-demi is located at /node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vue-demi/lib/index, but its own vue version is 3.2.13, not 2.7.16.

image

SwingCosmic avatar Feb 22 '24 08:02 SwingCosmic

There is an extra script to switch vueCompilerOptions.target before running these builds to make sure vue-loader can get correct vue version

SwingCosmic avatar Feb 22 '24 08:02 SwingCosmic