Skip to content

fix: correctly read env on workers#21

Closed
Barbapapazes wants to merge 1 commit intoHugoRCD:mainfrom
Barbapapazes:fix/wrong-env
Closed

fix: correctly read env on workers#21
Barbapapazes wants to merge 1 commit intoHugoRCD:mainfrom
Barbapapazes:fix/wrong-env

Conversation

@Barbapapazes
Copy link
Contributor

@Barbapapazes Barbapapazes commented Jan 31, 2026

Hey 👋,

To init the logger for a Cloudflare Workers, we have to do it outsite of the main fetch:

import { initlogger } from 'evlog'

initLogger()

export default {
	fetch(request: Request): Response {
		return new Response("Hello world")
	}
}

However, process isn't defined so isDev is always false, even in production where NODE_ENV is set to production.

I think it could be solve by importing node:env but it could have some undesirable side-effects. So, I think using globalThis is a better solution and to avoid to add to much complexity to your package, I propose std-env that makes it easy.

@vercel
Copy link

vercel bot commented Jan 31, 2026

@Barbapapazes is attempting to deploy a commit to the HRCD Projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions bot added the bug Something isn't working label Jan 31, 2026
@github-actions
Copy link

github-actions bot commented Jan 31, 2026

Thank you for following the naming conventions! 🙏

@Barbapapazes
Copy link
Contributor Author

Barbapapazes commented Jan 31, 2026

it does not work

related to unjs/std-env#162

@Barbapapazes
Copy link
Contributor Author

The only way to have it to work is by using cloudflare:workers

import { env } from 'cloudflare:workers'
import { initLogger, createRequestLogger } from 'evlog'

initLogger({
  pretty: env.NODE_ENV !== 'production',
})

@Barbapapazes
Copy link
Contributor Author

Maybe, we should dedicate a section to explain how to use evlog with Cloudflare Workers at it don't seems to be fixable.

@HugoRCD
Copy link
Owner

HugoRCD commented Jan 31, 2026

Maybe, we should dedicate a section to explain how to use evlog with Cloudflare Workers at it don't seems to be fixable.

Will this work if the issue is fixed ? Maybe we can push the issue ?

@HugoRCD HugoRCD closed this Feb 4, 2026
@Barbapapazes Barbapapazes deleted the fix/wrong-env branch February 5, 2026 00:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants