Error: `Could not find file` when extraneous TS files in project and `declaration: true`
See original GitHub issueWhat happens and why it is wrong
In a project using rollup-plugin-typescript2.
- The project generates a library, so I need it to create type declarations as well as the JS bundle.
- I have typescript files which are not built into the main project.
Compiling results in
Rolling back https://github.com/ezolenko/rollup-plugin-typescript2/commit/ffe3b6cd9fc03611460aac15d2b880fab7a7d093 fixes this error.
Environment
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
Versions
- typescript: 2.9.2
- rollup: 0.62.0
- rollup-plugin-typescript2: 0.15.1
rollup.config.js
// 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"
}
}
the rest of the code
// extra/extra.ts
console.log('read all about it');
// index.ts
module.exports = 1;
plugin output with verbosity 3
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>
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Issue: TypeScript not finding the declaration file - Stack Overflow
I am trying to build a class in User and then have a interface declaration for an object I use in User.d.ts. I...
Read more >eslint-import-resolver-typescript - npm
Start using eslint-import-resolver-typescript in your project by running `npm i eslint-import-resolver-typescript`.
Read more >Changelog - Cypress Documentation
Fixed a regression introduced in Cypress 12 where cy.get() would ignore a null ... for failed specs when the cypress config file is...
Read more >node_modules/eslint-plugin-import/docs/rules/no-extraneous ...
If no package.json is found, the rule will not lint anything. ... setting will be set to true (no errors reported) if the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Looks like the fix for virtual modules (https://github.com/ezolenko/rollup-plugin-typescript2/issues/78#issuecomment-399524537) broke the hack for declarations missing because they are invisible to rollup…
Confirmed the fix, thanks!