nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.77k stars 2.37k forks source link

@nx/rollup/plugin can’t resolve tsconfig.json #28438

Open drwpow opened 1 month ago

drwpow commented 1 month ago

Current Behavior

Given the following rollup.config.js in a monorepo (simplified):

// packages/react-color-picker/rollup.config.json

import ts from '@rollup/plugin-typescript';

/** @type {import("rollup").InputOptions} */
export default {
  plugins: [
    ts({
      tsconfig: './tsconfig.build.json',
    }),
  ]
};

Trying to run @nx/rollup/plugin results in the following error:

 NX   Failed to process project graph. Run "nx reset" to fix this. Please report the issue if you keep seeing it. See errors below.

Failed to process project graph. Run "nx reset" to fix this. Please report the issue if you keep seeing it.
      An error occurred while processing files for the @nx/rollup/plugin plugin.
    - packages/react-color-picker/rollup.config.js: Could not find specified tsconfig.json at /Users/drew/Sites/terrazzoapp/terrazzo/tsconfig.build.json
      Error: Could not find specified tsconfig.json at /Users/drew/Sites/terrazzoapp/terrazzo/tsconfig.build.json
          at getTsConfigPath (file:///Users/drew/Sites/terrazzoapp/terrazzo/node_modules/.pnpm/@rollup+plugin-typescript@11.1.6_rollup@4.24.0_tslib@2.7.0_typescript@5.6.3/node_modules/@rollup/plugin-typescript/dist/es/index.js:244:19)
          at parseTypescriptConfig (file:///Users/drew/Sites/terrazzoapp/terrazzo/node_modules/.pnpm/@rollup+plugin-typescript@11.1.6_rollup@4.24.0_tslib@2.7.0_typescript@5.6.3/node_modules/@rollup/plugin-typescript/dist/es/index.js:318:26)
          at typescript (file:///Users/drew/Sites/terrazzoapp/terrazzo/node_modules/.pnpm/@rollup+plugin-typescript@11.1.6_rollup@4.24.0_tslib@2.7.0_typescript@5.6.3/node_modules/@rollup/plugin-typescript/dist/es/index.js:754:27)
          at file:///Users/drew/Sites/terrazzoapp/terrazzo/packages/react-color-picker/rollup.config.js?1728965200242:12:5
          at ModuleJob.run (node:internal/modules/esm/module_job:262:25)
          at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:483:26)
          at async getConfigFileExport (/Users/drew/Sites/terrazzoapp/terrazzo/node_modules/.pnpm/rollup@4.24.0/node_modules/rollup/dist/shared/loadConfigFile.js:471:17)
          at async loadConfigFile (/Users/drew/Sites/terrazzoapp/terrazzo/node_modules/.pnpm/rollup@4.24.0/node_modules/rollup/dist/shared/loadConfigFile.js:430:59)
          at async buildRollupTarget (/Users/drew/Sites/terrazzoapp/terrazzo/node_modules/.pnpm/@nx+rollup@20.0.0_@babel+core@7.25.8_@babel+traverse@7.25.7_@swc+core@1.7.35_@swc+helpers@0.5_ffvo47yijgt2k62ikoudbwsnj4/node_modules/@nx/rollup/src/plugins/plugin.js:70:27)
          at async exports.createNodes (/Users/drew/Sites/terrazzoapp/terrazzo/node_modules/.pnpm/@nx+rollup@20.0.0_@babel+core@7.25.8_@babel+traverse@7.25.7_@swc+core@1.7.35_@swc+helpers@0.5_ffvo47yijgt2k62ikoudbwsnj4/node_modules/@nx/rollup/src/plugins/plugin.js:41:32)

Basically it’s looking for [projectRoot]/tsconfig.base.json when it should be looking for /packages/react-color-picker/tsconfig.base.json

Expected Behavior

Rollup plugins resolve relative to rollup.config.js, rather than cwd or project root

GitHub Repo

https://github.com/terrazzoapp/terrazzo/pull/317/

Steps to Reproduce

  1. Checkout nx branch
  2. Run pnpm i
  3. Run pnpm run build

(search for rollup.config.js files)

Nx Report

 NX   Report complete - copy this into the issue template

Node           : 22.9.0
OS             : darwin-arm64
Native Target  : aarch64-macos
pnpm           : 9.12.1

nx             : 20.0.0
@nx/js         : 20.0.0
@nx/eslint     : 20.0.0
@nx/workspace  : 20.0.0
@nx/cypress    : 20.0.0
@nx/devkit     : 20.0.0
@nx/rollup     : 20.0.0
@nx/storybook  : 20.0.0
@nx/vite       : 20.0.0
@nx/web        : 20.0.0
typescript     : 5.6.3
---------------------------------------
Registered Plugins:
@nx/vite/plugin
@nx/rollup/plugin
---------------------------------------
⚠️ Unable to construct project graph.
Failed to process project graph. Run "nx reset" to fix this. Please report the issue if you keep seeing it.
Failed to process project graph. Run "nx reset" to fix this. Please report the issue if you keep seeing it.
      An error occurred while processing files for the @nx/rollup/plugin plugin.
    - packages/react-color-picker/rollup.config.js: Could not find specified tsconfig.json at /Users/drew/Sites/terrazzoapp/terrazzo/tsconfig.build.json
      Error: Could not find specified tsconfig.json at /Users/drew/Sites/terrazzoapp/terrazzo/tsconfig.build.json
          at getTsConfigPath (file:///Users/drew/Sites/terrazzoapp/terrazzo/node_modules/.pnpm/@rollup+plugin-typescript@11.1.6_rollup@4.24.0_tslib@2.7.0_typescript@5.6.3/node_modules/@rollup/plugin-typescript/dist/es/index.js:244:19)
          at parseTypescriptConfig (file:///Users/drew/Sites/terrazzoapp/terrazzo/node_modules/.pnpm/@rollup+plugin-typescript@11.1.6_rollup@4.24.0_tslib@2.7.0_typescript@5.6.3/node_modules/@rollup/plugin-typescript/dist/es/index.js:318:26)
          at typescript (file:///Users/drew/Sites/terrazzoapp/terrazzo/node_modules/.pnpm/@rollup+plugin-typescript@11.1.6_rollup@4.24.0_tslib@2.7.0_typescript@5.6.3/node_modules/@rollup/plugin-typescript/dist/es/index.js:754:27)
          at file:///Users/drew/Sites/terrazzoapp/terrazzo/packages/react-color-picker/rollup.config.js?1728965523594:12:5
          at ModuleJob.run (node:internal/modules/esm/module_job:262:25)
          at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:483:26)
          at async getConfigFileExport (/Users/drew/Sites/terrazzoapp/terrazzo/node_modules/.pnpm/rollup@4.24.0/node_modules/rollup/dist/shared/loadConfigFile.js:471:17)
          at async loadConfigFile (/Users/drew/Sites/terrazzoapp/terrazzo/node_modules/.pnpm/rollup@4.24.0/node_modules/rollup/dist/shared/loadConfigFile.js:430:59)
          at async buildRollupTarget (/Users/drew/Sites/terrazzoapp/terrazzo/node_modules/.pnpm/@nx+rollup@20.0.0_@babel+core@7.25.8_@babel+traverse@7.25.7_@swc+core@1.7.35_@swc+helpers@0.5_ffvo47yijgt2k62ikoudbwsnj4/node_modules/@nx/rollup/src/plugins/plugin.js:70:27)
          at async exports.createNodes (/Users/drew/Sites/terrazzoapp/terrazzo/node_modules/.pnpm/@nx+rollup@20.0.0_@babel+core@7.25.8_@babel+traverse@7.25.7_@swc+core@1.7.35_@swc+helpers@0.5_ffvo47yijgt2k62ikoudbwsnj4/node_modules/@nx/rollup/src/plugins/plugin.js:41:32)
    - packages/tiles/rollup.config.js: Could not find specified tsconfig.json at /Users/drew/Sites/terrazzoapp/terrazzo/tsconfig.build.json
      Error: Could not find specified tsconfig.json at /Users/drew/Sites/terrazzoapp/terrazzo/tsconfig.build.json
          at getTsConfigPath (file:///Users/drew/Sites/terrazzoapp/terrazzo/node_modules/.pnpm/@rollup+plugin-typescript@12.1.0_rollup@4.24.0_tslib@2.7.0_typescript@5.6.3/node_modules/@rollup/plugin-typescript/dist/es/index.js:247:19)
          at parseTypescriptConfig (file:///Users/drew/Sites/terrazzoapp/terrazzo/node_modules/.pnpm/@rollup+plugin-typescript@12.1.0_rollup@4.24.0_tslib@2.7.0_typescript@5.6.3/node_modules/@rollup/plugin-typescript/dist/es/index.js:321:26)
          at typescript (file:///Users/drew/Sites/terrazzoapp/terrazzo/node_modules/.pnpm/@rollup+plugin-typescript@12.1.0_rollup@4.24.0_tslib@2.7.0_typescript@5.6.3/node_modules/@rollup/plugin-typescript/dist/es/index.js:768:27)
          at file:///Users/drew/Sites/terrazzoapp/terrazzo/packages/tiles/rollup.config.js?1728965523597:12:5
          at ModuleJob.run (node:internal/modules/esm/module_job:262:25)
          at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:483:26)
          at async getConfigFileExport (/Users/drew/Sites/terrazzoapp/terrazzo/node_modules/.pnpm/rollup@4.24.0/node_modules/rollup/dist/shared/loadConfigFile.js:471:17)
          at async loadConfigFile (/Users/drew/Sites/terrazzoapp/terrazzo/node_modules/.pnpm/rollup@4.24.0/node_modules/rollup/dist/shared/loadConfigFile.js:430:59)
          at async buildRollupTarget (/Users/drew/Sites/terrazzoapp/terrazzo/node_modules/.pnpm/@nx+rollup@20.0.0_@babel+core@7.25.8_@babel+traverse@7.25.7_@swc+core@1.7.35_@swc+helpers@0.5_ffvo47yijgt2k62ikoudbwsnj4/node_modules/@nx/rollup/src/plugins/plugin.js:70:27)
          at async exports.createNodes (/Users/drew/Sites/terrazzoapp/terrazzo/node_modules/.pnpm/@nx+rollup@20.0.0_@babel+core@7.25.8_@babel+traverse@7.25.7_@swc+core@1.7.35_@swc+helpers@0.5_ffvo47yijgt2k62ikoudbwsnj4/node_modules/@nx/rollup/src/plugins/plugin.js:41:32)

Failure Logs

No response

Package Manager Version

pnpm 9.12.1

Operating System

Additional Information

Running nx reset didn’t fix the issue (it seems to be a problem with the Rollup plugin)

drwpow commented 1 month ago

Found a workaround:

  // packages/react-color-picker/rollup.config.json

+ import { fileURLToPath } from 'node:url';
  import ts from '@rollup/plugin-typescript';

  /** @type {import("rollup").InputOptions} */
  export default {
    plugins: [
      ts({
-       tsconfig: './tsconfig.build.json',
+       tsconfig: fileURLToPath(new URL('./tsconfig.build.json', import.meta.url)),
      }),
    ]
  };

This just gives an absolute filepath to the plugin. Which may be an underlying issue with this Rollup plugin, and not Nx