Description
Importance
The Rollup TypeScript plugin cannot handle files that are located in a sub-directory: rollup/plugins#287
This is the #1 most reported bug in the Rollup ecosystem (i.e. including both the core package and all plugins) with over 100 thumbs up on the issue
Overview
tsc
uses getSourceFilePathInNewDir
to find out where the output is placed. However, this method is not exposed. Thus, the Rollup plugin must use getOutputFileNames
, which often returns incorrectly.
TypeScript Version: 4.1.2
Search Terms: getOutputFileNames
Code
I wrote a unit test that fails.
I know the TypeScript team gets an insane amount of bug reports. I hope you might bear with me a little bit on this one given how widely used Rollup is and how many people this is impacting as noted above.
The call to getOutputFileNames
is made in src/outputFile.ts
. I added some console.log
statements that show the options it's being called with. It seems pretty clear to me that this is a bug because none of the option values reference the src
directory specifically. The outDir
is correctly showing the dist/
directory.
I pushed this to my fork of the Rollup plugins. (You can install pnpm with npm install -g pnpm
if you do not have it)
git clone [email protected]:benmccann/plugins.git
cd plugins
git checkout src-dir-test-enabled
pnpm install
cd packages/typescript
pnpm ts-bug
pnpm ts-bug
is an npm script that runs a single unit test I added, which fails because of this bug. Running it will print to the console the arguments passed to getOutputFileNames
and result from it
Expected behavior:
getOutputFileNames
should return dist/index.js
Actual behavior:
getOutputFileNames
returns dist/src/index.js
Playground Link:
Related Issues:
- Expose
getOutputJavaScriptFileName
from tsbuild #26410 - issue where it was requested that this functionality be exposed - Typescript plugin 4.0.0 Error: Unexpected token (Note that you need plugins to import files that are not JavaScript) rollup/plugins#287 - Rollup TypeScript plugin fails due to this issue