-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Windows: @nx/rollup:rollup fails due to joinPathFragments stripping drive letter #35092
Copy link
Copy link
Open
Open
Copy link
Labels
Description
Current Behavior
Building a library with @nx/rollup:rollup executor on Windows fails with:
RollupError: The "fileName" or "name" properties of emitted chunks and assets
must be strings that are neither absolute nor relative paths,
received "../../../../libs/lib/src/index.d.ts".
This happens because @nx/rollup uses joinPathFragments() to construct the tsconfig path:
// packages/rollup/src/plugins/with-nx/with-nx.ts:47
const tsConfigPath = options.buildLibsFromSource || global.NX_GRAPH_CREATION
? joinPathFragments(workspaceRoot, options.tsConfig) // ← BUG
: createTmpTsConfig(...);However, joinPathFragments() internally calls removeWindowsDriveLetter(), which strips the Windows drive letter:
// packages/nx/src/utils/path.ts
function removeWindowsDriveLetter(osSpecificPath) {
return osSpecificPath.replace(/^[a-zA-Z]:/, '');
}
/**
* Converts an os specific path to a unix style path. Use this when writing paths to config files.
* This should not be used to read files on disk because of the removal of Windows drive letters.
*/
function normalizePath(osSpecificPath) {
return removeWindowsDriveLetter(osSpecificPath).split('\\').join('/');
}
function joinPathFragments(...fragments) {
return normalizePath(path.join(...fragments));
}This path propagates to parsedConfig.fileNames in rollup-plugin-typescript2, causing the generateBundle hook to emit duplicate declaration files with relative paths like ../../../../libs/....
Expected Behavior
The build should succeed on Windows. @nx/rollup should use path.join() instead of joinPathFragments() when constructing paths that will be used to read files from disk.
Fix:
- ? joinPathFragments(workspaceRoot, options.tsConfig)
+ ? path.join(workspaceRoot, options.tsConfig)GitHub Repo
No response
Steps to Reproduce
- Create an Nx 21 workspace on Windows
- Generate a library with
@nx/rollup:rollupexecutor - Enable
declaration: truein tsconfig - Run
npx nx build <library-name> - Build fails with the RollupError above
Nx Report
Node : 20.19.5
OS : win32-x64
Native Target : x86_64-windows
npm : 10.8.2
nx : 21.0.0
@nx/js : 21.0.0
@nx/rollup : 21.0.0
@nx/devkit : 21.0.0
typescript : 5.7.3Failure Logs
> nx run lib:build
RollupError: The "fileName" or "name" properties of emitted chunks and assets must be strings that are neither absolute nor relative paths, received "../../../../libs/ce/src/index.d.ts".
at error (file:///D:/dev/project/node_modules/rollup/dist/es/shared/node-entry.js:2248:30)
at Object.emitFile (file:///D:/dev/project/node_modules/rollup/dist/es/shared/node-entry.js:13812:24)
at emitDeclaration (D:\dev\project\node_modules\rollup-plugin-typescript2\dist\rollup-plugin-typescript2.cjs.js:28237:26)
at Object.generateBundle (D:\dev\project\node_modules\rollup-plugin-typescript2\dist\rollup-plugin-typescript2.cjs.js:28245:21)Package Manager Version
No response
Operating System
- macOS
- Linux
- Windows
- Other (Please specify)
Additional Information
Root Cause Analysis:
@nx/rollupcallsjoinPathFragments(workspaceRoot, tsConfig)→/dev/project/tsconfig.lib.json(missingD:)- This path is passed to rollup-plugin-typescript2 as the
tsconfigoption parseTsConfig()uses this path →parsedConfig.fileNamesall have/dev/...paths (no drive letter)- In
generateBundle, the checkkey in declarationsfails because:declarationskeys:D:/dev/project/libs/my-lib/src/index.tsparsedConfig.fileNameskeys:/dev/project/libs/my-lib/src/index.ts
- Duplicate declarations are generated with broken paths
path.relative()on mismatched paths produces../../../../...traversals- Rollup rejects this in
emitFile()
Workaround:
Apply patch to @nx/rollup:
- ? (0, devkit_1.joinPathFragments)(devkit_1.workspaceRoot, options.tsConfig)
+ ? (0, node_path_1.join)(devkit_1.workspaceRoot, options.tsConfig)npx patch-package @nx/rollupReactions are currently unavailable