-
Notifications
You must be signed in to change notification settings - Fork 6
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
Add support for edge runtimes #2
Comments
Thanks for the report! I'm not using any Node-incompatible runtimes and don't have plans to do so... that said, On the other hand, Do you know if conditionally requiring Incidentally, other colour modules seem to suffer from the same issue. |
@lostfictions FWIW I think supporting browsers would be a huge value-add for this library, especially given that |
To give a specific example of how this would be used: webpack plumbs environment variables into app code using |
@dctalbot Would gratefully accept PRs for this! One asterisk about solutions like So I definitely understand the value-add and that there are good use cases, but I'm worried that this will also become a common source of confusion. I'm happy to support browsers on a best-effort basis, but I'd like any PR to make sure these caveats are well-documented in the README. Does that sound reasonable? Finally, if this work can be done by removing |
Nice, I agree supporting ES modules is more important. Thanks for the note of caution - it's funny you mention that because I had the same realization/concern when working with this code recently. create-react-app replaces Instead of clobbering const stringified = {
'MY_APP_ENV_CONFIG': Object.keys(raw).reduce((env, key) => {
env[key] = JSON.stringify(raw[key]);
return env;
}, {}),
}; In app code: const env = znv.parse(MY_APP_ENV_CONFIG) On server: const env = znv.parse(process.env) IMO supporting other runtimes is still worthwhile, but agreed that any examples in documentation should steer clear of this pitfall. |
@slowbaker Could you try the latest version of Example (with nextjs app router) and edge route handler: import { parseEnv } from 'bowlingx-znv'
import { NextResponse } from 'next/server'
import { z } from 'zod'
export const runtime = 'edge'
const testConfig = parseEnv(process.env, {
NODE_ENV: z.string()
})
export async function GET(request: Request) {
return NextResponse.json({ env: testConfig.NODE_ENV })
} https://codesandbox.io/p/sandbox/relaxed-bogdan-cz9qvk?file=/app/api/route.ts:7,43 |
I've just opened #15 which should add edge runtime support via a separate entrypoint -- could folks here who requested this feature take a look and see if it works for you? I've published it to npm under the |
I am seeing the following now
tried using the |
I overlooked the note to use |
Znv causes an error if it's run "on the edge" (for example on Vecel's Edge Runtime).
The
tty
module is used bycolorette
.The text was updated successfully, but these errors were encountered: