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

找不到名称“process” #2072

Closed
SheepYang1993 opened this issue Apr 12, 2024 · 7 comments
Closed

找不到名称“process” #2072

SheepYang1993 opened this issue Apr 12, 2024 · 7 comments
Labels
🐞 bug Something isn't working

Comments

@SheepYang1993
Copy link

Version

{
  "name": "demo",
  "private": true,
  "version": "1.0.0",
  "scripts": {
    "dev": "rsbuild dev --open",
    "build": "rsbuild build",
    "preview": "rsbuild preview"
  },
  "dependencies": {
    "axios": "^1.6.8",
    "crypto-js": "^4.2.0",
    "jsencrypt": "^3.3.2",
    "qs": "^6.12.0",
    "ts-md5": "^1.3.1",
    "vant": "^4.8.10",
    "vue": "^3.4.19",
    "vue-router": "4"
  },
  "devDependencies": {
    "@rsbuild/core": "^0.5.9",
    "@rsbuild/plugin-rem": "^0.5.9",
    "@rsbuild/plugin-vue": "^0.5.9",
    "typescript": "^5.4.2"
  }
}

Details

const baseURL = process.env.PUBLIC_BASE_URL ?? "";

找不到名称“process”。是否需要安装 Node.js 的类型定义? 请尝试运行 npm i --save-dev @types/node

Reproduce link

none

Reproduce Steps

none

@SheepYang1993 SheepYang1993 added the 🐞 bug Something isn't working label Apr 12, 2024
@chenjiahan
Copy link
Member

报错信息已经很明确了

@SheepYang1993
Copy link
Author

报错信息已经很明确了

我是用的pnpm,执行pnpm add -D @types/node装完后,process没报错了,但是process.env.VUE_APP_BASE_URL还是没读取到值。

console报错,Uncaught ReferenceError: process is not defined

有在src目录下配置.env.development.env.production文件,里面只有一个值VUE_APP_BASE_URL=http://xxx.xxx.xxx.xxx:xxxx

@9aoy
Copy link
Collaborator

9aoy commented Apr 12, 2024

.env 文件放在项目根目录下哈,不是 src 下
https://rsbuild.dev/zh/guide/advanced/env-vars#env-%E6%96%87%E4%BB%B6

@SheepYang1993
Copy link
Author

SheepYang1993 commented Apr 12, 2024

.env 文件放在项目根目录下哈,不是 src 下 https://rsbuild.dev/zh/guide/advanced/env-vars#env-%E6%96%87%E4%BB%B6

已放置在根目录下,还是提示Uncaught ReferenceError: process is not defined
image
image
image

@SheepYang1993
Copy link
Author

这是我的配置文件
image
image

@9aoy
Copy link
Collaborator

9aoy commented Apr 12, 2024

要 PUBLIC_ 开头的自定义环境变量才可以在 client 代码中访问,你看下文档介绍
https://rsbuild.dev/zh/guide/advanced/env-vars#public-%E5%8F%98%E9%87%8F

@SheepYang1993
Copy link
Author

PUBLIC_

改成PUBLIC_ 开头,可以读取到了,感谢指导!

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

3 participants