TS7016

error TS7016: Could not find a declaration file for module ‘uuidjs‘.

Broken Code ❌

1
import UUID = require('uuidjs');

Fixed Code ✔️

The problem shows that uuidjs is a plain JavaScript module and doesn’t ship with TypeScript declaration files (.d.ts). That’s why we have to use the CommonJS import syntax to import this module in a Node.js project:

main.ts
1
const UUID = require('uuidjs');

A proper fix would be to have a uuidjs.d.ts as part of uuidjs: https://github.com/LiosK/UUID.js/issues/6

Example:

uuidjs.d.ts
1
2
3
declare class UUID {
static generate(): string;
}
main.ts
1
2
import UUID from 'uuidjs';
const id = UUID.generate();