fix(pack): add createRequire as global API in loader worker and fix hmr#2762
Merged
Conversation
- Expose createRequire on self (global) in the CJS loader worker,
enabling loaders to use createRequire(filename) to get a require
function anchored at a given path
- Update module/node:module polyfill to return { createRequire }
so require('module').createRequire also works
- Update next.js submodule with wasm file write and
available_parallelism improvements
Contributor
There was a problem hiding this comment.
Code Review
This pull request updates the next.js subproject and implements a custom createRequire function within the CJS loader. The node:module and module polyfills are updated to utilize this new function. Feedback suggests implementing a singleton pattern for these polyfills to ensure module identity consistency and improve performance.
…r update diffing - Fix hmr_version_state to use an operation function with .read_trait_strongly_consistent().untracked() matching the Next.js pattern. Without .untracked(), the VersionState was re-created on every content change with the new version, causing content.update(from) to always compare identical versions and return Update::None. - Fix hmr_identifiers to use client_root() instead of dist_root(). Output chunk assets are stored on the virtual client-fs filesystem, so keys_in_path(dist_root) on the output-fs could only find stats.json.
fireairforce
approved these changes
Apr 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
packages/utoo-web/src/webpackLoaders/cjs.tscreateRequireonself(global) inside thecjs()function, so webpack loaders can usecreateRequire(filename)to get arequirefunction that resolves modules relative topath.dirname(filename)packages/utoo-web/src/webpackLoaders/polyfills/nodePolyFills.tsmodule/node:modulepolyfill getters to return{ createRequire }from the global, sorequire('module').createRequireandimport { createRequire } from 'module'both worknext.jssubmoduleavailable_parallelismimprovements (feat(turbopack): wasm file write support and available_parallelism for worker pool next.js#138)crates/pack-api/src/project.rs— Fix HMR updates always returningUpdate::NoneTwo bugs were fixed:
hmr_version_statewas re-creating VersionState on every change — The old implementation usedversion.into_trait_ref().await?which is tracked, causing turbo-tasks to re-executehmr_version_statewhenever content changed. This created a newVersionStateinitialized with the new version, socontent.update(from)always compared identical versions →Update::None. Fixed by using an inner#[turbo_tasks::function(operation)]with.read_trait_strongly_consistent().untracked(), matching the Next.js implementation.hmr_identifiersuseddist_root()instead ofclient_root()— Output chunk assets are stored on the virtualclient-fsfilesystem, butkeys_in_path(dist_root)queries theoutput-fs, which only containedstats.json. Changed toclient_root()to match howhmr_content()andemit_all_output_assets()use the same root.