Search code examples
typescriptvitetsconfig

Howto solve the Problem with "ESNext" support in the default Vite/Vue project Template


Update

I found the reason. It's the order of settings in the tsconfig files.

I have created a GIT repository where it can be reproduced.
https://github.com/MBurchard/2024-12-04-vite-test

The problem is that the Vite and Vue project generator creates the files the way they do.

However, I am not in a position to judge what exactly the fault is.
Should the order not matter?
Does vitest have to run with ‘lib’: []?

Initial Question

I have created a brand new project with pnpm create vite, decided to us Vue with 'Customize with create-vue' and used 'Typescript': enter image description here

These are the generated dependencies:

"dependencies": {
    "pinia": "^2.2.6",
    "vue": "^3.5.13",
    "vue-router": "^4.4.5"
  },
  "devDependencies": {
    "@tsconfig/node22": "^22.0.0",
    "@types/jsdom": "^21.1.7",
    "@types/node": "^22.9.3",
    "@vitejs/plugin-vue": "^5.2.1",
    "@vitest/eslint-plugin": "1.1.10",
    "@vue/eslint-config-typescript": "^14.1.3",
    "@vue/test-utils": "^2.4.6",
    "@vue/tsconfig": "^0.7.0",
    "eslint": "^9.14.0",
    "eslint-plugin-vue": "^9.30.0",
    "jsdom": "^25.0.1",
    "npm-run-all2": "^7.0.1",
    "typescript": "~5.6.3",
    "vite": "^6.0.1",
    "vite-plugin-vue-devtools": "^7.6.5",
    "vitest": "^2.1.5",
    "vue-tsc": "^2.1.10"
  },

After using pnpm i within the project folder I wanted to test, why I got this error on another project, so I added this code into the HomeView.vue:

const test: string = "Hello";
const result = test.replaceAll(/\s/g, '')
console.log(result);

At first Visual Studio code marked replaceAll as an error. As usual, I added lib to the tsconfig.app.json file.

"lib": [
  "DOM",
  "ESNext",
],

Now, VS Code was satisfied, but the build task from package.json not: enter image description here

Usually ESNext covers ES2021, but of course I tried to change that, but that didn't fix the error either.

Am I on the tube, or is this a bug in Vite?

Is someone able to reproduce this problem?


Solution

  • The answer is now described in the question above.

    I have not yet received a response and cannot judge the nature and quality of the error.