-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
[Bug]: process
is not defined when build with cloudflare pages
#1285
Comments
This is not a bug, Cloudflare Worker doesn’t use use Node and process is a Node thing, therefore process is not available in CF. Note that process.env.NODE_ENV it’s still available there because Remix replace it with the hard coded value on build. |
Is there an API to specify additional For example, one might want to have access to the CF_PAGES_COMMIT_SHA to include for Sentry or something? |
i'll have a try |
Was a solution ever discovered for this? I'm also curious |
There’s no solution, it’s not a bug, you need to use env variables in the way they work in Cloudflare not using process as in Node because Cloudflare doesn’t use Node As far as I know, in Cloudflare Workers env variables are global variables and in Cloudflare Pages you will get them in the loader and action functions with the context object. |
first, add context to functions: // /functions/[[path]].ts
import { createPagesFunctionHandler } from '@remix-run/cloudflare-pages';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import * as build from '../build';
const handleRequest = createPagesFunctionHandler({
build,
getLoadContext: (context) => context
});
export const onRequest: PagesFunction = (context) => handleRequest(context); then you can get it from loader: export const loader: LoaderFunction = async ({ context }) => {
const { env } = context;
return json({ env });
}; |
@willin - Thanks, this worked within the deployment version but how would you get that working in development locally i.e. |
I just did some digging into all this today! It seems like in an earlier stage folks were customizing their As of a more recent version, however, the cloudflare-pages example that @IamManchanda if you want to use an env variable in local dev you need to ensure that
|
Thanks @jemjam you saved me a lot of hassle! I'm going to do a PR to update the docs, because this is the only place I found where someone had the current answer. |
Anyone know how you can read this in server only code? Like when using |
@bondz did you find an answer for this? Env variables are also needed outside of the loader and action functions as well. |
@jgb-solutions Not yet, sadly. I started a discussion at #3581 in case anyone wants to contribute. |
@bondz okay nice! |
Which Remix packages are impacted?
remix
(Remix core)create-remix
@remix-run/architect
@remix-run/cloudflare-workers
@remix-run/dev
@remix-run/express
@remix-run/netlify
@remix-run/node
@remix-run/react
@remix-run/serve
@remix-run/server-runtime
@remix-run/vercel
What version of Remix are you using?
"@remix-run/cloudflare-pages": "^1.1.1"
What version of Node are you using? Minimum supported version is 14.
17.2
Steps to Reproduce
https://github.com/js-cool/remix-blog-demo/blob/main/app/utils/enviroment.ts#L17
Expected Behavior
work properly
Actual Behavior
cannot build
The text was updated successfully, but these errors were encountered: