Skip to content

Revert "fix(wrangler): handling of process.env.NODE_ENV in bundling mode"#7967

Merged
edmundhung merged 1 commit intomainfrom
revert-7932-bundle/process-env
Jan 30, 2025
Merged

Revert "fix(wrangler): handling of process.env.NODE_ENV in bundling mode"#7967
edmundhung merged 1 commit intomainfrom
revert-7932-bundle/process-env

Conversation

@edmundhung
Copy link
Copy Markdown
Member

Reverts #7932.

@edmundhung edmundhung added skip-pr-description-validation Skip validation of the required PR description format no-changeset-required labels Jan 29, 2025
@edmundhung edmundhung requested a review from a team as a code owner January 29, 2025 20:29
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jan 29, 2025

⚠️ No Changeset found

Latest commit: 5f55c3d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 29, 2025

A wrangler prerelease is available for testing. You can install this latest build in your project with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13048240333/npm-package-wrangler-7967

You can reference the automatically updated head of this PR with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/7967/npm-package-wrangler-7967

Or you can use npx with this latest build directly:

npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13048240333/npm-package-wrangler-7967 dev path/to/script.js
Additional artifacts:

cloudflare-workers-bindings-extension:

wget https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13048240333/npm-package-cloudflare-workers-bindings-extension-7967 -O ./cloudflare-workers-bindings-extension.0.0.0-va3dea7b1b.vsix && code --install-extension ./cloudflare-workers-bindings-extension.0.0.0-va3dea7b1b.vsix

create-cloudflare:

npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13048240333/npm-package-create-cloudflare-7967 --no-auto-update

@cloudflare/kv-asset-handler:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13048240333/npm-package-cloudflare-kv-asset-handler-7967

miniflare:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13048240333/npm-package-miniflare-7967

@cloudflare/pages-shared:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13048240333/npm-package-cloudflare-pages-shared-7967

@cloudflare/unenv-preset:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13048240333/npm-package-cloudflare-unenv-preset-7967

@cloudflare/vite-plugin:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13048240333/npm-package-cloudflare-vite-plugin-7967

@cloudflare/vitest-pool-workers:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13048240333/npm-package-cloudflare-vitest-pool-workers-7967

@cloudflare/workers-editor-shared:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13048240333/npm-package-cloudflare-workers-editor-shared-7967

@cloudflare/workers-shared:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13048240333/npm-package-cloudflare-workers-shared-7967

@cloudflare/workflows-shared:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13048240333/npm-package-cloudflare-workflows-shared-7967

Note that these links will no longer work once the GitHub Actions artifact expires.


wrangler@3.106.0 includes the following runtime dependencies:

Package Constraint Resolved
miniflare workspace:* 3.20250124.0
workerd 1.20250124.0 1.20250124.0
workerd --version 1.20250124.0 2025-01-24

Please ensure constraints are pinned, and miniflare/workerd minor versions match.

@petebacondarwin
Copy link
Copy Markdown
Contributor

Can you provide some explanation why this is being reverted?

@lrapoport-cf
Copy link
Copy Markdown
Contributor

Can you provide some explanation why this is being reverted?

my understanding is that although #7932 indicates in the PR description that it has tests, they're actually missing from that PR. so this revert is to go back until tests can be added. @edmundhung @vicb is this correct?

@vicb
Copy link
Copy Markdown
Contributor

vicb commented Jan 30, 2025

I think that is the case, my answer to @edmundhung yesterday

You're absolutely right, tests are not included, I definitely should have mentioned that.
There is one more point to be fixed in the original issue (when process is imported rather than using the global) that definitely needs testing.
This PR only includes the fix that are obvious but I can understand if it cannot be merged without tests.

@vicb
Copy link
Copy Markdown
Contributor

vicb commented Jan 30, 2025

To be clear:

  • I think that the current code is broken
  • I think that the reverted PR fixes some of the issues
  • The current is not tested (properly or at all, that I don't know)
  • I think the reverted PR is an improvement
  • BUT I fully understand why no test is a reason to revert the PR... i.e. we wouldn't have broken in the first place if we caught that it was not tested.

I think it would be good to add test soon and fixed the remaining point in the original issue

@edmundhung
Copy link
Copy Markdown
Member Author

I have prepared this PR just in case we are feeling uncomfortable with the changes for today's release. But happy to close this if we have no concern :) Personally I think the change is minimal and it is quite clear what it fixed.

@vicb
Copy link
Copy Markdown
Contributor

vicb commented Jan 30, 2025

I'll defer to others for the decision.

Whatever the decision, I think #7886 should be prioritized.

@penalosa
Copy link
Copy Markdown
Contributor

@vicb @edmundhung I think the change is minimal and shouldn't cause issues (if it would, we'd see other tests failing). However, perhaps @vicb you could add a simple test that checks that Wrangler correctly statically defines process.env.NODE_ENV? The navigator define is already tested.

In terms of fixing the imported process, personally I think we should punt on that until the runtime solution lands, since the situation right now is stable.

@vicb vicb closed this Jan 30, 2025
@vicb vicb reopened this Jan 30, 2025
@vicb
Copy link
Copy Markdown
Contributor

vicb commented Jan 30, 2025

@vicb @edmundhung I think the change is minimal and shouldn't cause issues (if it would, we'd see other tests failing). However, perhaps @vicb you could add a simple test that checks that Wrangler correctly statically defines process.env.NODE_ENV? The navigator define is already tested.

Could you point me to a starting point (i.e. existing test)?

In terms of fixing the imported process, personally I think we should punt on that until the runtime solution lands, since the situation right now is stable.

Are you thinking of cloudflare/workerd#3311?
If that's the case I think that it should be considered orthogonal.
Quite a few libs out there have debug code guarded by if (process.env.NODE === "development") { ... } (or similar). While having the value at runtime would make sure the code is not executed, it would still be in the bundle (including potential dependencies).
Having process.env.NODE replaced at build time would ensure the code is tree shaken and would allow reducing the bundle size.
(Also 3311 is paused and will be guarded by a compatibility flag when released)

@penalosa
Copy link
Copy Markdown
Contributor

@edmundhung
Copy link
Copy Markdown
Member Author

We will revert this as agreed and will land this change again once we have the test ready 👍🏼

@edmundhung edmundhung merged commit 9ba6374 into main Jan 30, 2025
@edmundhung edmundhung deleted the revert-7932-bundle/process-env branch January 30, 2025 15:32
@edmundhung edmundhung mentioned this pull request Jan 30, 2025
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-changeset-required skip-pr-description-validation Skip validation of the required PR description format

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

5 participants