remix.run部署在vercel上:过程未定义错误
我已经在Vercel上部署了一个混音应用程序。此外,我已经在Vercel中定义了一些环境变量,并想执行一些检查并在我的应用程序中使用ENV变量:
if (process.env.NODE_ENV === 'production') {
setPaths({
path: process.env.prod_path,
})
}
它给了我错误,过程未定义
。我什至尝试在语句中添加 process&&
,这无济于事。
其次,我什至无法在本地设置ENV变量。我关注 remix docs ,但它给了我未定义的
每次i console.log
如文档中所述。
在混音中使用环境变量的任何指南/指针都将确实很有帮助。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我能够解决这个问题。我正在使用Loader/useloaderdata访问服务器端环境变量。问题在于我试图将其称为组件级别。显然,我们只能在路线级别打电话。
I was able to solve this problem. I was using loader/useLoaderData to access server side environment variables. The problem was that I was trying to call these at component level. Apparently, we can only call them at the route level.
我不确定,但是该函数的名称(setxxx让我认为这是钩子的设置),让我认为您正在尝试在浏览器中使用Process.env,但是Process.env仅在服务器中可用 - 侧代码,如果要在React应用中使用ENV变量,则可以使用本指南将变量从服务器端发送到您的React应用程序。如果此代码是服务器端代码,则可能值得在Stackblitz中复制,因此我们可以更好地查看它。
I'm not sure, but the name of the function (setXXX makes me think this is the setter of a hook), makes me think you are trying to use process.env in the browser, but process.env is only available in server-side code, if you want to use env variables in your react app you can use this guide to send the variables from the server side to you react app. If this code is server side code, maybe it's worth making a reproduction in stackblitz so we can have a better look at it.