Error: Module “crypto“ has been externalized for browser compatibility and cannot be accessed in ...

背景

使用vite构建项目的时候需要用到crypto进行加密出现的错误。问题出在vite本身使用了crypto,我们如果通过npm i crypto -S会导致vite构建时报错。

Error: Module "crypto" has been externalized for browser compatibility
and cannot be accessed in client code.

解决

采用js-md5来进行加密。https://www.npmjs.com/package/js-md5

相关api转换

- crypto.update("xxx")
+ md5.update("xxx");

- crypto.digest
+ md5.hex();

你可能感兴趣的:(笔记,javascript,vue.js,react)