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.

Could not find a declaration file for module 'uuid' (Incompatibility with ES6 Import)

See original GitHub issue

I’m using TypeScript inside my project. If I try to use ES5 import style like const { v4: uuidv4 } = require('uuid'); So I don’t get any error while compilation but when I convert it into ES6 style like import { v4 as uuidv4 } from 'uuid'; I get a compilation error like Could not find a declaration file for module 'uuid'. 'C:/Users/project/dependencies/nodejs/node_modules/uuid/dist/index.js' implicitly has an 'any' type. Try 'npm i --save-dev @types/uuid' if it exists or add a new declaration (.d.ts) file containing 'declare module 'uuid';'

I tried the available solutions to fix this kind of error but nothing worked. In the end I created a new declaration file inside node_modules/uuid/ and named it index.d.ts

And add the following line to fix the issue:

declare module 'uuid';

And then the error is gone.

Can anyone fix this type of issue?

Issue Analytics

  • State:closed
  • Created 9 months ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
LinusUcommented, Dec 20, 2022

Hmm, I’m not able to reproduce this:

$ cd /tmp
$ mkdir jhdska
$ cd jhdska 
$ echo {} > package.json
$ npm add uuid @types/uuid typescript 

added 3 packages, and audited 4 packages in 676ms

found 0 vulnerabilities
$ cat > test.ts
import { v4 as uuidv4 } from 'uuid'

console.log(uuidv4())
<ctrl+d>
$ tsc test.ts
$ node test.js
b7c77fbb-95d0-4b88-b9ba-89dba2912d5d
1reaction
LinusUcommented, Dec 20, 2022

It’s impossible for me to know what you mean with “all possible solution” 😅 If you mean that literally, then there is nothing I can do to help since all the possible solutions are already tried…

After installing @types/uuid, do you still get the exact same error message?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Could not find a declaration file for module 'module-name ...
In order for this to work, I had to make declare module '...' the first line of code in the module.d.ts file, and...
Read more >
Could not find declaration file for module 'uuid' | bobbyhadz
The error "could not find declaration file for module uuid " occurs when TypeScript cannot find the type declaration for a uuid-related module....
Read more >
How to fix error TS7016: Could not find a declaration file for ...
Try `npm install @types/XYZ` if it exists or add a new declaration (. d. ts) file containing `declare module 'XYZ'; If XYZ is...
Read more >
Could not find a declaration file for module #66 - GitHub
Bug report I am importing a specific file from a library on npm, e.g. import file1 from 'someLib/src/file1'. To get its types to...
Read more >
Typescript Typings: The Complete Guide: @types Compiler ...
we are using the ES6 import syntax to import something from an ES6 module named uuid; we are saying that the module will...
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