plugins icon indicating copy to clipboard operation
plugins copied to clipboard

[@rollup/plugin-typescript] `--configPlugin` command option with Typescript plugin doesn't support `reference` option in tsconfig.json.

Open Mingeax opened this issue 1 year ago • 4 comments

  • Rollup Plugin Name: @rollup/plugin-typescript
  • Rollup Plugin Version: 7.15.0
  • Rollup Version: v4.20.0
  • Operating System (or Browser): Windows 10
  • Node Version: v20.13.1
  • Link to reproduction (⚠️ read below): https://stackblitz.com/edit/rollup-repro-hfhjsp

Expected Behavior

Output successfully.

Actual Behavior

Throw error: Note that you need plugins to import files that are not JavaScript.

Additional Information

The rollup config file is include with the tsconfig file in references array.

Mingeax avatar Aug 12 '24 08:08 Mingeax

same here, any solution?

tsconfig.json

{
  "files": ["./dist/atomsbuildinfo"], // this root tsconfig just exists to compose sub-projects
  "references": [
    {
      "path": "./src"
    },
    {
      "path": "./src/components/atoms"
    },
    {
      "path": "./src/components/molecules"
    },
    {
      "path": "./src/components/organisms"
    }
  ]
}

src\components\atoms\tsconfig.json


{
  "extends": "../../../tsconfig-base.json",
  "compilerOptions": {
    "outDir": "../../../dist",
    "composite": true, // needed for references sub-projects
    "rootDir": ".",
    "tsBuildInfoFile": "../../../dist/atomsbuildinfo",
    "rootDirs": [
      "../../../src",
      "../../../src/component/atoms",
      "../../../src/component/molecules",
      "../../../src/component/organisms"
    ]
  },
  "references": [
    {
      "path": "../../../src" // test project depends on src
    }
  ]
}

tsconfig-base.json


{
  // see https://www.typescriptlang.org/tsconfig to better understand tsconfigs
  // "include": ["./src/**/*/*"],
  "compilerOptions": {
    "allowJs": true,
    // output .d.ts declaration files for consumers
    "declaration": true,
    "declarationDir": "./dist",
    // interop between ESM and CJS modules. Recommended by TS
    "esModuleInterop": true,
    // error out if import and file system have a casing mismatch. Recommended by TS
    "forceConsistentCasingInFileNames": true,
    "importHelpers": true,
    // transpile JSX to React.createElement
    "jsx": "react",
    "lib": ["dom", "esnext"],
    "module": "esnext",
    // use Node's module resolution algorithm, instead of the legacy TS one
    "moduleResolution": "node",
    // `tsdx build` ignores this option, but it is commonly used when type-checking separately with `tsc`
    "noEmit": false,
    "noFallthroughCasesInSwitch": true,
    // linter checks for common issues
    "noImplicitReturns": true,
    // noUnused* overlap with @typescript-eslint/no-unused-vars, can disable if duplicative
    "noUnusedLocals": false,
    "noUnusedParameters": false,
    // match output dir to input dir. e.g. dist/index instead of dist/src/index
    "rootDir": "./src",
    "outDir": "./dist",
    // "baseUrl": "./src",
    // "paths": {
    //   "*": ["*"]
    // },
    // significant perf increase by skipping checking .d.ts files, particularly those in node_modules. Recommended by TS
    "skipLibCheck": true,
    // output .js.map sourcemap files for consumers
    "sourceMap": true,
    // stricter type-checking for stronger correctness. Recommended by TS
    "strict": true,
    "typeRoots": ["./src/types", "node_modules/@types"],
    // "emitDeclarationOnly": true
    "target": "es6",
    "build": true
  }
}

hsnMoghadasi avatar Sep 25 '24 10:09 hsnMoghadasi

Also running into this. Replacing my base tsconfig.json with my tsconfig.rollup.json allows rollup to handle rollup.config.ts, but obviously the rest of my project breaks.

  • Rollup Plugin Name: @rollup/plugin-typescript
  • Rollup Plugin Version: 12.1.0
  • Rollup Version: v4.22.5
  • Operating System (or Browser): Linux
  • Node Version: v22.9.0

tsconfig.json

{
	"files": [],
	"references": [
		{ "path": "./tsconfig.integrations.json" },
		{ "path": "./tsconfig.rollup.json" },
		{ "path": "./tsconfig.service-worker.json" },
	],
}

tsconfig.rollup.json

{
	"include": ["./rollup.config.ts"],
	"compilerOptions": {
		"composite": true,
		"noEmit": true,
		"esModuleInterop": true,
		"module": "ESNext",
		"moduleResolution": "Bundler",
		"lib": ["ESNext"],
	}
}

crunk1 avatar Oct 02 '24 18:10 crunk1

Ah it appears to not only break for rollup.config.ts, but my other files as well. I converted rollup.config.ts to mjs and I saw the same Note that you need plugins to import files that are not JavaScript for other files in my project.

crunk1 avatar Oct 02 '24 18:10 crunk1

its work for me in rollup config change the tsconfig to './tsconfig-base.json

   plugins: [
      typescript({ tsconfig: './tsconfig-base.json' }),
      ]

and use this command to make the d.ts files

yarn tsc -b -v

hsnMoghadasi avatar Oct 05 '24 13:10 hsnMoghadasi

Hey folks. This issue hasn't received any traction for 60 days, so we're going to close this for housekeeping. If this is still an ongoing issue, please do consider contributing a Pull Request to resolve it. Further discussion is always welcome even with the issue closed. If anything actionable is posted in the comments, we'll consider reopening it.

stale[bot] avatar Apr 27 '25 01:04 stale[bot]