Definitelytyped: [@types/uuid] - v7.0.0 breaks `uuid/v4`

Created on 26 Feb 2020  Â·  10Comments  Â·  Source: DefinitelyTyped/DefinitelyTyped

  • [X] I tried using the @types/uuid package and had problems.
  • [X] I tried using the latest stable version of tsc. https://www.npmjs.com/package/typescript
  • [X] I have a question that is inappropriate for StackOverflow. (Please ask any appropriate questions there).
  • [X] [Mention](https://github.com/blog/821-mention-somebody-they-re-notified) the authors (see Definitions by: in index.d.ts) so they can respond.

    • Authors: @iamolivinius, @felipeochoa, @cjbarth, @rauno56, @LinusU, and @ctavan

Imports of uuid/v4 broke today as no declaration file found after update to @types/uuid v7.0.0

Could not find a declaration file for module 'uuid/v4'. '/Users/pete.burkindine/git/ccxp/ccxp-client/node_modules/uuid/v4.js' implicitly has an 'any' type.
  Try `npm install @types/uuid` if it exists or add a new declaration (.d.ts) file containing `declare module 'uuid/v4';`

Most helpful comment

For anyone else experiencing this,

import { v4 as uuid } from 'uuid';
rather than
import * as uuid from 'uuid/v4';
The changelog for uuid indicates
Explicitly note that deep imports of the different uuid version functions are 
deprecated and no longer encouraged and that ECMAScript module named imports 
should be used instead. Emit a deprecation warning for people who deep-require 
the different algorithm variants.

... however I received no deprecation notice before or after updating @types/uuid

All 10 comments

For anyone else experiencing this,

import { v4 as uuid } from 'uuid';
rather than
import * as uuid from 'uuid/v4';
The changelog for uuid indicates
Explicitly note that deep imports of the different uuid version functions are 
deprecated and no longer encouraged and that ECMAScript module named imports 
should be used instead. Emit a deprecation warning for people who deep-require 
the different algorithm variants.

... however I received no deprecation notice before or after updating @types/uuid

@pburkindine good catch, seems like I was a bit too fast when updating the types.

We could easily bring back types for the deep imports as long as we make sure they result in a depreciation warning. I admit that we should not treat typescript users differently than JS users.

I can look into this later this week but would be equally happy to review a pull request.

Could not find a declaration file for module 'uuid/v4'. 'c:/.../node_modules/uuid/v4.js' implicitly has an 'any' type.

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


import { v4 as uuidv4 } from "uuid/v4";

...


export function randomId(): string {
  return uuidv4();
}

TypeError: Object(...) is not a function at randomId

@gokhantaskan

-import { v4 as uuidv4 } from "uuid/v4";
+import { v4 as uuidv4 } from "uuid";

The deep requires have been deprecated as of UUID version 7.x

@gokhantaskan

-import { v4 as uuidv4 } from "uuid/v4";
+import { v4 as uuidv4 } from "uuid";

The deep requires have been deprecated as of UUID version 7.x

#### But it still gives the same error. Also it was working when the file is .js

const { v4 } = require("uuid");

...

export function randomId(): string {
  return v4();
}

This code works.

@gokhantaskan this is really weird! The unit test of the type declarations uses

import { v4 as uuidv4 } from "uuid";

and it just works fine. What error do you get when using the above code?

See: https://github.com/ctavan/DefinitelyTyped/blob/5a59a59b867088e492e59e9f52ec681a9ff5b7a2/types/uuid/uuid-tests.ts#L3

This breaks other packages that build over uuid like: https://github.com/VitorLuizC/vue-uuid
However they continue to work by installing @types/uuid v7.0.4 ✅

@zbianca I think this can easily be fixed in vue-uuid by changing

import v1 from 'uuid/v1';
import v4 from 'uuid/v4';
import v5 from 'uuid/v5';

to

import { v1, v4, v5 } from 'uuid';

in https://github.com/VitorLuizC/vue-uuid/blob/master/index.d.ts and https://github.com/VitorLuizC/vue-uuid/blob/master/index.js

This is something that has to be done in the vue-uuid package though, so I think you may have to raise an issue or send a pull request over there.

@ctavan Thanks for the quick reply!

I'll raise an issue over there 🙂

Incase anyone has come here from google - make sure your @types/uuid matches the version of your uuid.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JudeAlquiza picture JudeAlquiza  Â·  3Comments

lilling picture lilling  Â·  3Comments

variousauthors picture variousauthors  Â·  3Comments

ArtemZag picture ArtemZag  Â·  3Comments

fasatrix picture fasatrix  Â·  3Comments