-
-
Notifications
You must be signed in to change notification settings - Fork 774
Description
System Info
System:
OS: Linux 6.8 Ubuntu 24.04.3 LTS 24.04.3 LTS (Noble Numbat)
CPU: (2) arm64 unknown
Memory: 2.52 GB / 5.77 GB
Container: Yes
Shell: 5.2.21 - /bin/bash
Binaries:
Node: 24.13.0 - /usr/bin/node
npm: 11.6.2 - /usr/bin/npm
npmPackages:
@rspack/core: ^2.0.0-beta.5 => 2.0.0-beta.5
Details
When consuming @rspack/core types with moduleResolution: "nodenext" (or "node16"), the Source type used throughout the package (e.g. Compilation.assets, Compilation.getAsset()) silently degrades to any.
This happens because dist/Compilation.d.ts imports Source via a bare directory path:
import type { Source } from '../compiled/webpack-sources';Under nodenext ESM resolution, TypeScript cannot resolve this path. The @rspack/core package has "type": "module", so dist/Compilation.d.ts is treated as ESM. In ESM mode, nodenext does not perform directory-to-package.jsonβtypes resolution for relative imports. The module fails to resolve, and Source falls back to any.
npx tsc --traceResolution confirms:
======== Resolving module '../compiled/webpack-sources' from 'node_modules/@rspack/core/dist/BuildInfo.d.ts'. ========
Resolution for module '../compiled/webpack-sources' was found in cache from location 'node_modules/@rspack/core/dist'.
======== Module name '../compiled/webpack-sources' was not resolved. ========
This affects all types that depend on Source, including:
Compilation.assetsβRecord<string, any>instead ofRecord<string, Source>Compilation.getAsset()βSourcefield becomesanyCompilation.emitAsset()/updateAsset()parameter typesAssetstype alias (Record<string, Source>)sourcesnamespace re-export
Reproduce link
https://github.com/pikadun/rspack-source-type
Reproduce Steps
- npm install
- npm run test