2 回答

TA贡献1852条经验 获得超7个赞
在花费数小时研究和审查我的代码后,我找到了我的应用程序无法在 Heroku 上运行的原因。那是因为客户端使用dotenv模块,我在webpack.config.js:
//...requirements
const dotenv = require("dotenv");
const webpack = require("webpack");
module.exports = {
//...configs
plugins: [
//...other plugins
new webpack.DefinePlugin({
"process.env": JSON.stringify(dotenv.parsed)
})
]
};
然后当我在 Heroku 上部署我的应用程序时,Heroku 将从源代码构建我的客户端,服务器将在dist文件夹中查找前端部分。客户端现在无法.env在 Heroku 上找到该文件,因此无法加载导致其抛出错误的环境变量。

TA贡献1883条经验 获得超3个赞
问题不在于您粘贴的代码,或者至少我对此表示怀疑。如果您在线查看该模块,您会看到它具有以下检查:
// If debug isn't set in LS, and we're in Electron, try to load $DEBUG
if (!r && typeof process !== 'undefined' && 'env' in process) {
r = process.env.DEBUG;
}
你会注意到它正在阅读它process.env,这是一个 Node 的东西/Electron 的东西。在客户端的控制台内,输入window.process,如果你得到了什么,可能就是这样。它正在检查process......可能是 webpack
添加回答
举报