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.cwd() is not a function #44

Closed
hb0730 opened this issue Sep 24, 2021 · 14 comments
Closed

process.cwd() is not a function #44

hb0730 opened this issue Sep 24, 2021 · 14 comments

Comments

@hb0730
Copy link
Contributor

hb0730 commented Sep 24, 2021

image
image
image
image

@hb0730
Copy link
Contributor Author

hb0730 commented Sep 24, 2021

当使用vite的LoadEnv时是可行的
image
image

@xiaoxian521
Copy link
Member

你修改这个文件就行了
image

@hb0730
Copy link
Contributor Author

hb0730 commented Sep 24, 2021

还有单独调用loadEnv方法,好像process.cwd()报错了
image

@xiaoxian521
Copy link
Member

并没有呢
image

@hb0730
Copy link
Contributor Author

hb0730 commented Sep 24, 2021

我是在router index.ts中单独调用,发现process.cwd报错,但是在vite.config.ts中调用process.cwd是没有问题的

image
image
image

难道无法再别的地方调用么~~

@xiaoxian521
Copy link
Member

比如你可以这样用:process.env.NODE_ENV

@xiaoxian521
Copy link
Member

别忘了设置这个
image

@hb0730
Copy link
Contributor Author

hb0730 commented Sep 24, 2021

image
image

这样可以保证loadEnv在任何地方不会抛出process.cwd is not a function

@xiaoxian521
Copy link
Member

是的,这样是可以的,但是当引入某些第三包时,会出现打包错误

@hb0730
Copy link
Contributor Author

hb0730 commented Sep 24, 2021

3817 有类似案例,仓库地址: vite_vue3_web3

@hb0730 hb0730 changed the title 更改环境PORT,貌似并未生效 process.cwd() is not a function Sep 24, 2021
@hb0730
Copy link
Contributor Author

hb0730 commented Sep 26, 2021

好像最终只需要
image
就行了,不需要其他插件

hb0730 added a commit to hb0730/vue-pure-admin that referenced this issue Sep 27, 2021
在调用build/util/loadEnv()函数时会报process.cwd() is not a function

pure-admin#44
xiaoxian521 pushed a commit that referenced this issue Sep 27, 2021
在调用build/util/loadEnv()函数时会报process.cwd() is not a function

#44
@xiaoxian521
Copy link
Member

好像最终只需要
image
就行了,不需要其他插件

这样打包部署会找不到process 我已经删除了此代码 请检查对你有没有影响

@hb0730
Copy link
Contributor Author

hb0730 commented Sep 29, 2021

好的,在更改之后,我在本地build 部署之后是可以正常运行的,之前这么做是因为dotenv 读取环境变量用到了node相关内置函数,现在应该没有什么影响

@AdminQQZ
Copy link

image
你们是怎么解决的来着,我没看懂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants