Nub v0.11.4 installs Yarn lockfiles the way Yarn does, writes pnpm-lock.yaml the way the pinned pnpm does, runs TypeScript written for "module": "commonjs" as CommonJS, and runs workspace packages from source before they're built.
A few changes can surface in an existing project, listed in Upgrading from v0.11.3.
Yarn lockfiles
Projects with a yarn.lock now install the same packages Yarn does (#1154, #1155, #1164). A Yarn 1 lockfile skipped every package's optionalDependencies, so platform bindings never installed and the parent failed:
Cannot find native binding. npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828).
What changed:
- Platform bindings. Yarn 1 and Yarn 2+ lockfiles install the host's binding for
@rolldown/binding-*,@esbuild/*,@rollup/rollup-*and the like, and only that one. Yarn 2+ installed every platform's as a required dependency. Fixes #1153. - Transitive dependencies. A Yarn 2+ lockfile's transitive dependencies and npm aliases link under the default isolated layout. They failed with
Cannot find module. file:dependencies. A Yarn 2+file:dependency installs, from the root or a workspace member. It was dropped.- Peer dependencies. Packages from a Yarn 1 or Yarn 2+ lockfile load their peers under the default isolated layout.
require('react-dom/server')failed withCannot find module 'react'. - Conversion to pnpm. A Yarn 2+ lockfile converted with
nub importornub pm use pnpmcarries integrity and links its workspace members, sopnpm install --frozen-lockfileaccepts it. --no-optional. Omits optional dependencies at every depth, for every lockfile kind. It dropped only the root's own.
pnpm lockfiles and .npmrc
A fresh resolve writes the same pnpm-lock.yaml keys as the pnpm major the project pins (#1166, #1175, #1176). Under a pnpm 10 pin, a peer named only in peerDependenciesMeta stays out of the key, as pnpm 10 writes it:
- debug@4.4.3(supports-color@7.2.0):
+ debug@4.4.3:What changed:
- Nested peers. A peer segment carries the peer's own peers, as in
(storybook@9.1.21(@testing-library/dom@10.4.2)(vite@7.3.8)). - Segment order. Segments sort by the whole
name@version(…)string, so(react-dom@…)comes before(react@…). - Peer cycles. A package on a peer cycle is named bare,
eslint-plugin-import@2.32.0, in every key that mentions it. - pnpm 9 and 10 pins. Peers named only in
peerDependenciesMetastay out of keys. Unpinned projects and pnpm 11 pins keep pnpm 11's keys. - List lines in
.npmrc. Onekey[]=valueline per item adds to a list, as npm and pnpm read them (#1172). These lines were ignored. - Existing lockfiles keep their keys.
Pruning and partial installs
The nub prune command and partial installs no longer delete packages the tree still uses (#1164). Each command now reads the graph the last install linked instead of working it out again from the lockfile:
echo 'public-hoist-pattern=*eslint*' >> .npmrc
nub install # links eslint and its plugins into the root node_modules
nub prune # keeps them; it deleted them beforeWhat changed:
- Peers. In a project installed from an npm or Bun lockfile,
nub prunedeleted every package that has a peer. - Public hoisting.
nub prunedeleted every packagepublic-hoist-patternlinks into the rootnode_modules, workspace members included, and the next install reported it up to date. - Per-project lockfiles.
nub pruneat the root of a workspace withshared-workspace-lockfile=falsedeleted the members' packages. --prod.nub prune --prodleft development-only versions in a hoisted tree, and after a hoisted--prodinstall it deleted transitive dependencies the tree needed.- Partial hoisted installs. A hoisted
--filterinstall, or a root install underrecursive-install=false, deleted what the other members had hoisted into the rootnode_modules. It now links every member the last install linked, as pnpm does. - Moved versions. A hoisted relink after a version moved between directories kept the old version in the moved one.
- Optional peers. Under the global virtual store, a package reaches an optional peer its ancestors don't provide, as pnpm's hidden hoist exposes it:
debugfindssupports-color.
TypeScript compiled to CommonJS
On Node 22.15 and later, a .ts or .tsx file whose tsconfig sets "module": "commonjs" runs as CommonJS, compiled the way tsc emits it (#1157, #1165). It ran as an ES module, so the first __dirname threw:
// tsconfig.json: { "compilerOptions": { "module": "commonjs" } }
import path from "node:path";
console.log(path.join(__dirname, "public"));What it covers:
- CommonJS globals.
__dirname,__filename,requireandmodulework besideimport, as under ts-node and tsx. - Packages without
"type": "module". The tsconfig wins over"type": "commonjs", where theimportwas refused before. - ES module importers. An
.mjsfile or an ES module package imports the compiled file and gets its named exports. import(). Returns whattsc's output returns, and stays a realimport()for an ES module that uses top-levelawaitorimport.meta.- Out of scope.
.mtsand.ctsfiles,"module": "node16"and"nodenext", and Node 22.14 and earlier keep their behavior, as does Node 22.15 to 24.11 or 25.0 to 25.1 with another--importor--loaderset.
Unbuilt workspace packages
When a workspace package's main, exports or imports names a file in its tsconfig outDir that doesn't exist yet, Nub loads the matching source under rootDir (#1156, #1170). A monorepo runs before anything is built:
// packages/lib/package.json: { "name": "lib", "main": "./dist/index.js" }
// packages/lib/tsconfig.json: { "compilerOptions": { "rootDir": "src", "outDir": "dist" } }
import lib from "lib"; // loads packages/lib/src/index.tsWhat it covers:
- Built files first. The fallback runs only after Node fails to find the file, so a built file always loads.
- Your resolve hooks first. A
module.registerorregisterHookshook, or aModule._resolveFilenamewrapper, sees Node's error before Nub maps it. - Extensions.
.jsmaps to.tsor.tsx,.mjsto.mts,.cjsto.cts. - The package's own tsconfig, with
extendsfollowed. WithoutrootDir, outputs map from the common directory of the files the tsconfig includes, astscinfers it, or from the tsconfig's directory. - Entry files. Running
nub dist/index.jsloadssrc/index.ts.
Upgrading from v0.11.3
-
Run
nub installonce after upgrading. A tree an earlier Nub linked from an npm, Bun or Yarn lockfile, and any tree in the global virtual store, is linked again by the next install. Until thennub prunerefuses:node_modules was linked by an older version help: run `nub install` before `nub prune` -
TypeScript under
"module": "commonjs"runs as CommonJS on Node 22.15 and later. A file that relied on running as an ES module can see these differences, as undertsc's output. Set"module"to"nodenext"to keep the old behavior.- An ES module importer gets the exports as they were when the file finished running, not live bindings.
- A static import of a file with top-level
awaitthrowsERR_REQUIRE_ASYNC_MODULE. - A cycle between an ES module and a compiled file throws
ERR_REQUIRE_CYCLE_MODULE. - An ES module that imports an
export =file gets onlydefault. __esModuleon a compiled file's exports is not enumerable.
-
Comma lists in a pnpm project's
.npmrc. Under a pnpm pin, a comma-separated value for a list setting such aspublic-hoist-patternis one pattern, as pnpm reads it (#1177). Write onekey[]=line per item. TheminimumReleaseAgeExcludesetting still splits on commas.
What's Changed
- pm: install transitive optionalDependencies from a yarn v1 lockfile by @colinhacks in #1154
- pm: link yarn berry transitive deps and filter its platform bindings by @colinhacks in #1155
- shim: add a remembered --no-modify-path flag by @colinhacks in #1140
- resolve: run a workspace package's source when its outDir isn't built by @colinhacks in #1156
- resolve: search a CommonJS bare subpath where Node searches by @colinhacks in #1158
- runtime: compile .ts to CommonJS under "module": "commonjs" by @colinhacks in #1157
- runtime: run a program whose
--requirepreload callsmodule.registerby @colinhacks in #1159 - ci: check Node flag defaults for drift and acknowledge the Node 28 changes by @colinhacks in #1163
- fix(store): detect missing dependency links in store status by @mvanhorn in #1160
- resolve: let Node answer first where a CommonJS caller chose the lookup by @colinhacks in #1161
- pm: link peer dependencies from a yarn.lock by @colinhacks in #1164
- docs: migrate /docs and /guides to Darjeeling by @colinhacks in #1167
- pm: write peer suffixes as pnpm does by @colinhacks in #1166
- runtime: fix what the CommonJS emit broke for "module": "commonjs" by @colinhacks in #1165
- docs: restore sidebar parity, header/footer actions, collapsible sidebar, and optical alignment by @colinhacks in #1171
- resolve: fix what the outDir source fallback broke by @colinhacks in #1170
- pm: read key[]= list lines in .npmrc by @colinhacks in #1172
- pm: name a package on a peer cycle bare in every key by @colinhacks in #1176
- pm: follow pnpm 9 and 10 for meta-only optional peers by @colinhacks in #1175
- pm: keep a pnpm .npmrc list value whole by @colinhacks in #1177
- pm: split a comma list of age-gate exclusions under pnpm by @colinhacks in #1178
- runtime: keep Nub's hooks in Node's hook thread by @colinhacks in #1174
- pm: treat a name in both dependencies and optionalDependencies as optional by @colinhacks in #1179
- runtime: wait for Node's import of the entry on the loader-worker tier by @colinhacks in #1180
- runtime: read a CommonJS entry off the module Node runs on the loader-worker tier by @colinhacks in #1183
- runtime: keep a user's require.cache accessor and serve unpredictable entries on the loader-worker tier by @colinhacks in #1184
New Contributors
Full Changelog: v0.11.3...v0.11.4