In a project using rollup-plugin-typescript2.
Compiling results in
Rolling back https://github.com/ezolenko/rollup-plugin-typescript2/commit/ffe3b6cd9fc03611460aac15d2b880fab7a7d093 fixes this error.
The following is the set of all files from a reproduction repo:
$ for f in $(git ls-files); do echo -e "\n// $f"; cat $f; done
// rollup.config.js
import typescript from 'rollup-plugin-typescript2';
export default {
input: 'index.ts',
output: [{ file: 'dist/index.js', format: 'es' }],
plugins: [
typescript({ verbosity: 3 }),
],
};
// tsconfig.json
{
"compilerOptions": {
"declaration": true
}
}
// package.json
{
"name": "@cht/demo-rollup-issue",
"private": true,
"engines": {
"node": ">=8"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"devDependencies": {
"rollup": "0.62.0",
"rollup-plugin-typescript2": "0.15.1",
"ts-node": "7.0.0",
"typescript": "2.9.2"
}
}
// extra/extra.ts
console.log('read all about it');
// index.ts
module.exports = 1;
index.ts → dist/index.js...
rpt2: typescript version: 2.9.2
rpt2: tslib version: 1.9.2
rpt2: rollup-plugin-typescript2 version: 0.15.1
rpt2: plugin options:
{
"verbosity": 3,
"check": true,
"clean": false,
"cacheRoot": "/tmp/cht-demo-rollup-issue/.rpt2_cache",
"include": [
"*.ts+(|x)",
"**/*.ts+(|x)"
],
"exclude": [
"*.d.ts",
"**/*.d.ts"
],
"abortOnError": true,
"rollupCommonJSResolveHack": false,
"typescript": "version 2.9.2",
"useTsconfigDeclarationDir": false,
"tsconfigOverride": {},
"transformers": [],
"tsconfigDefaults": {}
}
rpt2: rollup config:
{
"external": [
"",
""
],
"inlineDynamicImports": false,
"input": "index.ts",
"chunkGroupingSize": 5000,
"perf": false,
"plugins": [
{
"name": "rpt2"
}
],
"entry": "index.ts"
}
rpt2: built-in options overrides: {
"noEmitHelpers": false,
"importHelpers": true,
"noResolve": false,
"noEmit": false,
"inlineSourceMap": false,
"outDir": "/tmp/cht-demo-rollup-issue/.rpt2_cache/placeholder",
"moduleResolution": 2,
"declarationDir": "/tmp/cht-demo-rollup-issue"
}
rpt2: parsed tsconfig: {
"options": {
"module": 5,
"declaration": true,
"configFilePath": "/tmp/cht-demo-rollup-issue/tsconfig.json",
"noEmitHelpers": false,
"importHelpers": true,
"noResolve": false,
"noEmit": false,
"inlineSourceMap": false,
"outDir": "/tmp/cht-demo-rollup-issue/.rpt2_cache/placeholder",
"moduleResolution": 2,
"declarationDir": "/tmp/cht-demo-rollup-issue"
},
"fileNames": [
"/tmp/cht-demo-rollup-issue/index.ts",
"/tmp/cht-demo-rollup-issue/dist/index.d.ts",
"/tmp/cht-demo-rollup-issue/extra/extra.ts"
],
"typeAcquisition": {
"enable": false,
"include": [],
"exclude": []
},
"raw": {
"compilerOptions": {
"module": "ES2015",
"declaration": true
}
},
"errors": [],
"wildcardDirectories": {
"/tmp/cht-demo-rollup-issue": 1
},
"compileOnSave": false,
"configFileSpecs": {
"includeSpecs": [
"**/*"
],
"validatedIncludeSpecs": [
"**/*"
],
"wildcardDirectories": {
"/tmp/cht-demo-rollup-issue": 1
}
}
}
rpt2: included:
'[
"*.ts+(|x)",
"**/*.ts+(|x)"
]'
rpt2: excluded:
'[
"*.d.ts",
"**/*.d.ts"
]'
rpt2: [34mAmbient types:[39m
rpt2: /tmp/cht-demo-rollup-issue/dist/index.d.ts
rpt2: /tmp/cht-demo-rollup-issue/node_modules/@types/estree/index.d.ts
rpt2: /tmp/cht-demo-rollup-issue/node_modules/@types/node/index.d.ts
rpt2: [34mtranspiling[39m '/tmp/cht-demo-rollup-issue/index.ts'
rpt2: cache: '/tmp/cht-demo-rollup-issue/.rpt2_cache/7b3a3d6d8e402a4daa2232186da14bc2c8ade022/code/cache/6c8ae48d14e85933ce1e764b61d335b2aa5420f9'
rpt2: [32m cache hit[39m
rpt2: cache: '/tmp/cht-demo-rollup-issue/.rpt2_cache/7b3a3d6d8e402a4daa2232186da14bc2c8ade022/syntacticDiagnostics/cache/6c8ae48d14e85933ce1e764b61d335b2aa5420f9'
rpt2: [32m cache hit[39m
rpt2: cache: '/tmp/cht-demo-rollup-issue/.rpt2_cache/7b3a3d6d8e402a4daa2232186da14bc2c8ade022/semanticDiagnostics/cache/6c8ae48d14e85933ce1e764b61d335b2aa5420f9'
rpt2: [32m cache hit[39m
rpt2: [34mgenerated declarations[39m for '/tmp/cht-demo-rollup-issue/index.ts'
rpt2: generating target 1
rpt2: [34mrolling caches[39m
rpt2: generating missed declarations for '/tmp/cht-demo-rollup-issue/extra/extra.ts'
[!] Error: Could not find file: '/tmp/cht-demo-rollup-issue/extra/extra.ts'.
Error: Could not find file: '/tmp/cht-demo-rollup-issue/extra/extra.ts'.
at getValidSourceFile (/tmp/cht-demo-rollup-issue/node_modules/typescript/lib/typescript.js:107554:23)
at Object.getEmitOutput (/tmp/cht-demo-rollup-issue/node_modules/typescript/lib/typescript.js:108052:30)
at /tmp/cht-demo-rollup-issue/node_modules/rollup-plugin-typescript2/src/index.ts:311:29
at arrayEach (/tmp/cht-demo-rollup-issue/node_modules/rollup-plugin-typescript2/node_modules/lodash/lodash.js:516:11)
at forEach (/tmp/cht-demo-rollup-issue/node_modules/rollup-plugin-typescript2/node_modules/lodash/lodash.js:9342:14)
at Object.onwrite (/tmp/cht-demo-rollup-issue/node_modules/rollup-plugin-typescript2/src/index.ts:305:5)
at /tmp/cht-demo-rollup-issue/node_modules/rollup/dist/rollup.js:22076:39
at Array.map (<anonymous>)
at /tmp/cht-demo-rollup-issue/node_modules/rollup/dist/rollup.js:22075:18
at <anonymous>
Repo to reproduce here: https://github.com/amacleay/repro-rollup-plugin-ts2-declaration-issue (it's almost identically what is posted above)
Seems like this hits any file that isn't included by the import hierarchy. My test code, demos, and an unused file hit this. I worked around it for now by adding a few excludes to the rollup config for the things I wanted to skip.
Looks like the fix for virtual modules broke the hack for declarations missing because they are invisible to rollup...
Should be fixed now, try it in master.
I'll do a release soonish.
Confirmed the fix, thanks!
Most helpful comment
Looks like the fix for virtual modules broke the hack for declarations missing because they are invisible to rollup...