Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript error in .vue files: Cannot find name 'process' #1764

Closed
ataylor32 opened this issue Aug 26, 2022 · 8 comments
Closed

TypeScript error in .vue files: Cannot find name 'process' #1764

ataylor32 opened this issue Aug 26, 2022 · 8 comments
Labels
bug Something isn't working

Comments

@ataylor32
Copy link

I have a Vue project that was generated with Vue CLI. I have some VUE_APP_* variables that I access throughout my codebase by using process.env.VUE_APP_*. This works fine, but recently Visual Studio Code started showing an error for process in my .vue files. When I hover over it, this is what it says:

Cannot find name 'process'. Do you need to install type definitions for node? Try npm i --save-dev @types/node and then add 'node' to the types field in your tsconfig.ts(2591)

npm run serve doesn't show an error and the code works in the browser. In addition, process.env.VUE_APP_* works fine in .js and .ts files (Visual Studio Code doesn't report any errors with process and I can hover over it and it shows NodeJS.Process for its type). This also only happens with Volar. When I open the exact same codebase with Vetur instead of Volar, it works fine.

@ataylor32
Copy link
Author

I investigated some more and it looks like this bug was introduced with version 0.38.7.

@johnsoncodehk
Copy link
Member

I can't reproduce this problem with installed @types/node, please provide minimal reproduction.

image

@ataylor32
Copy link
Author

ataylor32 commented Aug 27, 2022

I will look into making a minimal reproduction, but did you try it with a project generated by Vue CLI?

@ataylor32
Copy link
Author

I still haven't made a minimal reproduction, but I did get more information. The problem seems to only occur when you add the parent folder in Visual Studio Code. For example, like this:

  1. mkdir example
  2. cd example
  3. vue create vueproject (Install TypeScript, but leave everything else set to the defaults)

After you do the above, if you add the "example" folder to Visual Studio Code then process doesn't work correctly in .vue files, but if you add the "vueproject" folder to Visual Studio Code then it does.

@johnsoncodehk
Copy link
Member

It may relate to #1679, please try v0.40.4 and let me know if it don't fix.

@ataylor32
Copy link
Author

The bug is still present in v0.40.4. Do you want an example repository or are the instructions I provided good enough?

@johnsoncodehk johnsoncodehk added bug Something isn't working and removed need info labels Sep 25, 2022
@jakenuts
Copy link

I fixed this by adding 'node' to the types in my tsconfig.json. After trying all the various webpack/define/process fixes I thought were the problem.

@mccxiv
Copy link

mccxiv commented Dec 28, 2023

For anyone reaching this thread today, if you're using Vite you need to change process.env to import.meta.env as per https://vitejs.dev/guide/env-and-mode#env-variables then make sure to have the vite types inside your tsconfig compilerOptions:

"types": [
  "vite/client"
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants