Skip to content

Windows: @nx/rollup:rollup fails due to joinPathFragments stripping drive letter #35092

@nkv843

Description

@nkv843

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

  1. Create an Nx 21 workspace on Windows
  2. Generate a library with @nx/rollup:rollup executor
  3. Enable declaration: true in tsconfig
  4. Run npx nx build <library-name>
  5. 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.3

Failure 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:

  1. @nx/rollup calls joinPathFragments(workspaceRoot, tsConfig)/dev/project/tsconfig.lib.json (missing D:)
  2. This path is passed to rollup-plugin-typescript2 as the tsconfig option
  3. parseTsConfig() uses this path → parsedConfig.fileNames all have /dev/... paths (no drive letter)
  4. In generateBundle, the check key in declarations fails because:
    • declarations keys: D:/dev/project/libs/my-lib/src/index.ts
    • parsedConfig.fileNames keys: /dev/project/libs/my-lib/src/index.ts
  5. Duplicate declarations are generated with broken paths
  6. path.relative() on mismatched paths produces ../../../../... traversals
  7. 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/rollup

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions