remix.run部署在vercel上:过程未定义错误

发布于 2025-01-26 06:10:03 字数 623 浏览 6 评论 0 原文

我已经在Vercel上部署了一个混音应用程序。此外,我已经在Vercel中定义了一些环境变量,并想执行一些检查并在我的应用程序中使用ENV变量:

  if (process.env.NODE_ENV === 'production') {
    setPaths({
      path: process.env.prod_path,
    })
  }

它给了我错误,过程未定义。我什至尝试在语句中添加 process&& ,这无济于事。

其次,我什至无法在本地设置ENV变量。我关注 remix docs ,但它给了我未定义的每次i console.log 如文档中所述。

在混音中使用环境变量的任何指南/指针都将确实很有帮助。

I have deployed a remix application on Vercel. Further, I have defined some environment variables in Vercel and want to perform some checks and use env variables in my app:

  if (process.env.NODE_ENV === 'production') {
    setPaths({
      path: process.env.prod_path,
    })
  }

It gives me error, process is not defined. I even tried adding process && in the if statement, it did not help.

Second, I am unable to even set the env variables locally. I followed remix docs but it gives me undefined every time when I console.log as mentioned in the docs.

Any guide/pointer towards using environmental variables in remix would be really helpful.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧时模样 2025-02-02 06:10:03

我能够解决这个问题。我正在使用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.

傲世九天 2025-02-02 06:10:03

我不确定,但是该函数的名称(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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文