@types/uuid package and had problems.Definitions by: in index.d.ts) so they can respond.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';`
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
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?
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.
Most helpful comment
For anyone else experiencing this,
rather than The changelog for uuid indicates... however I received no deprecation notice before or after updating
@types/uuid