question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Typescript: Could not find a declaration file for module 'sweetalert2/dist/sweetalert2.js'.

See original GitHub issue

Current behavior

TS giving that message above.

My TS config

{
    "compilerOptions": {
        "target": "esnext",
        "strict": true,
        "noEmit": true,
        "module": "esnext",
        "moduleResolution": "node",
        "esModuleInterop": true,
        "allowSyntheticDefaultImports": true,
        "baseUrl": ".",
        "typeRoots": [
            "./node_modules/@types",
            "./js/types"
        ]
    },
    "exclude": ["node_modules", "**/*.spec.ts"]
}

SweetAlert version: 9.7.1 Typescript version: 3.7.5

Expected behavior

Module shoud find declaration file even in dist and src folders

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
ainursharaevcommented, Jan 30, 2020

I’ve found solution. I added mainFields: ['module', 'browser', 'main'] field in my webpack config, because in your lib’s package.json you have this line - module": "src/sweetalert2.js"

1reaction
limontecommented, Jan 29, 2020

Thanks for the repo @nixta purplecandle!

The reason is that you’re setting "strict": true in your tsconfig. Add "noImplicitAny": false or any other solution from https://github.com/microsoft/TypeScript/issues/15031

The behavior doesn’t make much sense to me as well as to many commenters from https://github.com/microsoft/TypeScript/issues/15031 but it is what it is 🤷‍♂️

Read more comments on GitHub >

github_iconTop Results From Across the Web

Could not find a declaration file for module 'module-name ...
In Node.js everything works fine, but TypeScript: import {Injector} from '@ts-stack/di' ...
Read more >
Could not find declaration file for module 'X' Error | bobbyhadz
The error "Could not find a declaration file for module" occurs when TypeScript cannot find the type declaration for a module. To solve...
Read more >
How to fix error TS7016: Could not find a declaration file for ...
How to fix error TS7016: Could not find a declaration file for module 'XYZ'. 'file.js' implicitly has an 'any' type · Try `npm...
Read more >
Fixing the TS7016 Error | Atomist Blog
Could not find declaration file -- How do you get past the TS7016? ... When I import a JS module that is not...
Read more >
Using SweetAlert2 with TypeScript, cou.. - W3coded.com
Using SweetAlert2 with TypeScript, could not find a declaration file for module sweetalert2distsweetalert2.js javascript,sweetalert2,module,file,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found