vuejs / vetur

Vue tooling for VS Code.
https://vuejs.github.io/vetur/
MIT License
5.75k stars 594 forks source link

Vetur error Cannot find name 'process', and I already install @types/node. #2602

Closed OdaNeo closed 3 years ago

OdaNeo commented 3 years ago

Info

Problem

I create a vue2 project by vue-property-decorator to use typescript. And I find a problem while running such script in a .vue file. console.log(process.env.VUE_APP_BASE_API) It works in nodejs and my browser, but I just get a Vetur error:

Cannot find name 'process'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.Vetur(2580)

Actually, I already install @types/node. Here is my package.json:

{
  "name": "name",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "start": "vue-cli-service serve"
  },
  "dependencies": {
    "@better-scroll/core": "^2.0.0-beta.10",
    "@types/file-saver": "^2.0.1",
    "axios": "^0.19.2",
    "core-js": "^3.6.5",
    "echarts": "^4.8.0",
    "echarts-liquidfill": "^2.0.6",
    "file-saver": "^2.0.5",
    "moment": "^2.27.0",
    "vue": "^2.6.11",
    "vue-class-component": "^7.2.3",
    "vue-property-decorator": "^8.4.2",
    "vue-router": "^3.2.0",
    "vuetify": "^2.2.11",
    "vuex": "^3.4.0",
    "vuex-class": "^0.3.2",
    "vuex-module-decorators": "^0.17.0",
    "xlsx": "^0.16.9"
  },
  "devDependencies": {
    "@types/node": "^14.14.16",
    "@vue/cli-plugin-babel": "~4.4.0",
    "@vue/cli-plugin-router": "~4.4.0",
    "@vue/cli-plugin-typescript": "~4.4.0",
    "@vue/cli-plugin-vuex": "~4.4.0",
    "@vue/cli-service": "~4.4.0",
    "sass": "^1.19.0",
    "sass-loader": "^8.0.0",
    "stylus": "^0.54.8",
    "stylus-loader": "^3.0.2",
    "typescript": "~3.9.3",
    "vue-cli-plugin-vuetify": "~2.0.6",
    "vue-template-compiler": "^2.6.11",
    "vuetify-loader": "^1.3.0"
  },
  "browserslist": [
    "> 1%",
    "last 2 versions",
    "not dead"
  ]
}

To debug this, I just run console.log(process.env.VUE_APP_BASE_API) in a .ts file. It works, no bug, no error.

yoyo930021 commented 3 years ago

Please provide a repro case. Please read https://github.com/vuejs/vetur/blob/master/.github/NO_REPRO_CASE.md.

You may have this problem. https://vuejs.github.io/vetur/guide/FAQ.html#vetur-can-t-find-tsconfig-json-jsconfig-json-in-xxxx-xxxxxx

OdaNeo commented 3 years ago

Please provide a repro case. Please read https://github.com/vuejs/vetur/blob/master/.github/NO_REPRO_CASE.md.

You may have this problem. https://vuejs.github.io/vetur/guide/FAQ.html#vetur-can-t-find-tsconfig-json-jsconfig-json-in-xxxx-xxxxxx

I try overnight and I just find why. This project must at the root of vscode's workshape.After doing this, errors "Cannot find name 'process'" & "vetur cant find tsconfig.json" are gone. Thanks a lot! I can go sleep now ✌.