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

TS7016: Could not find a declaration file for module #807

Closed
AndyOGo opened this issue Feb 24, 2021 · 5 comments · Fixed by #888
Closed

TS7016: Could not find a declaration file for module #807

AndyOGo opened this issue Feb 24, 2021 · 5 comments · Fixed by #888
Labels
documentation has-fix A fix is available, but may not yet be released.

Comments

@AndyOGo
Copy link

AndyOGo commented Feb 24, 2021

Linting is okay, but the TS build with microbundle fails 🤔

I have a /types directory with two definition files and they are configured to be used by tsc with typeRoots.

https://github.com/AndyOGo/stylelint-declaration-strict-value/tree/master/types

https://github.com/AndyOGo/stylelint-declaration-strict-value/blob/7f9475d9f701ac9a1657f33b1f59aa184ab9727a/tsconfig.build.json#L8

> microbundle --tsconfig tsconfig.build.json --compress

(rpt2 plugin) Error: /home/travis/build/AndyOGo/stylelint-declaration-strict-value/src/index.ts(3,22): semantic error TS7016: Could not find a declaration file for module 'shortcss'. '/home/travis/build/AndyOGo/stylelint-declaration-strict-value/node_modules/shortcss/lib/index.js' implicitly has an 'any' type.

  Try `npm install @types/shortcss` if it exists or add a new declaration (.d.ts) file containing `declare module 'shortcss';`

Error: /home/travis/build/AndyOGo/stylelint-declaration-strict-value/src/index.ts(3,22): semantic error TS7016: Could not find a declaration file for module 'shortcss'. '/home/travis/build/AndyOGo/stylelint-declaration-strict-value/node_modules/shortcss/lib/index.js' implicitly has an 'any' type.

  Try `npm install @types/shortcss` if it exists or add a new declaration (.d.ts) file containing `declare module 'shortcss';`

    at error (/home/travis/build/AndyOGo/stylelint-declaration-strict-value/node_modules/rollup/dist/shared/node-entry.js:5400:30)

    at throwPluginError (/home/travis/build/AndyOGo/stylelint-declaration-strict-value/node_modules/rollup/dist/shared/node-entry.js:11878:12)

    at Object.error (/home/travis/build/AndyOGo/stylelint-declaration-strict-value/node_modules/rollup/dist/shared/node-entry.js:12912:24)

    at Object.error (/home/travis/build/AndyOGo/stylelint-declaration-strict-value/node_modules/rollup/dist/shared/node-entry.js:12081:38)

    at RollupContext.error (/home/travis/build/AndyOGo/stylelint-declaration-strict-value/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:17194:30)

    at /home/travis/build/AndyOGo/stylelint-declaration-strict-value/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:24958:23

    at arrayEach (/home/travis/build/AndyOGo/stylelint-declaration-strict-value/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:534:11)

    at forEach (/home/travis/build/AndyOGo/stylelint-declaration-strict-value/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:9360:14)

    at printDiagnostics (/home/travis/build/AndyOGo/stylelint-declaration-strict-value/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:24931:5)

    at Object.transform (/home/travis/build/AndyOGo/stylelint-declaration-strict-value/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:27374:17)

https://travis-ci.com/github/AndyOGo/stylelint-declaration-strict-value/builds/218179712#L2578-L2593

@AndyOGo AndyOGo changed the title TS7016: Could not find a declaration file for module 'shortcss' TS7016: Could not find a declaration file for module Feb 27, 2021
@AndyOGo
Copy link
Author

AndyOGo commented Feb 27, 2021

@AlexTilha
Copy link

The same issue, please fix.

@cloverhearts
Copy link

same issue ;D

@rschristian
Copy link
Collaborator

rschristian commented Sep 3, 2021

This looks to be an upstream issue in rpt2 as far as I can tell, doesn't seem to acknowledge typeRoots. Ah, nope, invalid test on my part.

We specify the files config option to limit which files Microbundle is actually processing, as the default for include is to cover just about every file/directory in the project, which leads to issues like #621.

typeRoots, which you've specified, doesn't actually alter what files TS includes. Specifying it on a directory that isn't included will do nothing as far as I can see from tests & the docs.

You need to use either include or files in your tsconfig.json to specify which files/paths you want Microbundle to include. As you've added neither, the default is for Microbundle to use your entry file and nothing else.

This is a bit awkward due to the nature of files & includes, as specifying the former alters the default for the latter. Need to think on how we can document this well.

@rschristian
Copy link
Collaborator

Pushed #888, hopefully that provides enough instruction to help avoid this issue.

If not, feel free to comment suggestions on that PR so that we can improve it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation has-fix A fix is available, but may not yet be released.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants