Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Could not find file when extraneous TS files in project and declaration: true #95

Closed
amacleay opened this issue Jun 29, 2018 · 5 comments
Assignees
Labels
kind: regression Specific type of bug -- past behavior that worked is now broken
Milestone

Comments

@amacleay
Copy link

amacleay commented Jun 29, 2018

What 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 ffe3b6c 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>

@amacleay
Copy link
Author

amacleay commented Jun 29, 2018

Repo to reproduce here: https://github.com/amacleay/repro-rollup-plugin-ts2-declaration-issue (it's almost identically what is posted above)

@mfedderly
Copy link

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.

@ezolenko ezolenko self-assigned this Jul 5, 2018
@ezolenko
Copy link
Owner

ezolenko commented Jul 5, 2018

Looks like the fix for virtual modules (#78 (comment)) broke the hack for declarations missing because they are invisible to rollup...

@ezolenko
Copy link
Owner

ezolenko commented Jul 6, 2018

Should be fixed now, try it in master.

I'll do a release soonish.

@amacleay
Copy link
Author

amacleay commented Jul 6, 2018

Confirmed the fix, thanks!

@ezolenko ezolenko added this to the 0.16.0 milestone Jul 10, 2018
@agilgur5 agilgur5 added the kind: regression Specific type of bug -- past behavior that worked is now broken label May 22, 2022
@agilgur5 agilgur5 changed the title Rollup compilation error when extraneous TS files in project and generating declaration files Error: Could not find file when extraneous TS files in project and declaration: true May 22, 2022
Repository owner locked as resolved and limited conversation to collaborators May 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind: regression Specific type of bug -- past behavior that worked is now broken
Projects
None yet
Development

No branches or pull requests

4 participants