TS7016

Could not find a declaration file for module 'uuidjs'.

Broken Code ❌

import UUID = require('uuidjs');

Fixed Code ✔️

Solution 1

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 environment:

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

Solution 2

A proper fix would be to have a uuidjs.d.ts as part of uuidjs (see GitHub issue).

Example:

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

Solution 3

If external typings are available in the DefinitelyTyped repository, then you can also install external declarations from there:

npm i --save-dev @types/uuidjs

Solution 4

If there are no declarations available and you want to use the module (in this case uuidjs) with standard import syntax (not CommonJS), then you can create a shorthand ambient module declaration by creating a "*.d.ts" file and writing the following into it:

types.d.ts
declare module 'uuidjs';

Video Tutorial