Skip to content

Commit df258cb

Browse files
committed
fix: handle missing nodejs crypto
1 parent 2dd5f72 commit df258cb

File tree

1 file changed

+6
-2
lines changed
  • packages/components-vue/src/composables

1 file changed

+6
-2
lines changed

packages/components-vue/src/composables/uuid.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ export default function useUIID() {
1212
// this should fail in node
1313
self.crypto || window.crypto;
1414
} catch (error) {
15-
// inject crypto into the global scope
16-
global.crypto = global.crypto || require("crypto");
15+
try {
16+
// inject crypto into the global scope
17+
global.crypto = global.crypto || require?.("crypto");
18+
} catch (error) {
19+
console.log("cannot define crypto");
20+
}
1721
}
1822

1923
return { uuid: nanoid };

0 commit comments

Comments
 (0)