TypeError: crypto.createCipheriv is not a function
Describe the bug
I use vuecli4 to build the project, using ace-cross to encrypt the request interface parameters can work normally; however, using vite to build the vue3 project, the console throws an error: TypeError: crypto.createCipheriv is not a function
Version: "vue": "^3.2.23", "vite": "^2.6.4", "aes-cross": "^1.0.9",
Reproduction
https://github.com/LQS5858/newmall-vue3-vite.git
System Info
System:
OS: macOS 11.6
CPU: (8) x64 Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz
Memory: 87.95 MB / 16.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 14.15.4 - /usr/local/bin/node
Yarn: 1.22.10 - /usr/local/bin/yarn
npm: 6.14.15 - /usr/local/bin/npm
Browsers:
Safari: 14.1.2
Used Package Manager
npm
Logs
No response
Validations
- [X] Follow our Code of Conduct
- [X] Read the Contributing Guidelines.
- [X] Read the docs.
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [X] Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/vue-next instead.
- [X] Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- [X] The provided reproduction is a minimal reproducible example of the bug.
It's not a bug. aes-cross depends on crypto, which is a node module and cannot be used in browsers.
It's not a bug.
aes-crossdepends oncrypto, which is a node module and cannot be used in browsers.
Hello,Is there a solution in vite
Find a polyfill for crypto? Or try with plugins like rollup-plugin-polyfill-node and vite-plugin-commonjs-externals? Not sure if they can works
Find a polyfill for crypto? Or try with plugins like rollup-plugin-polyfill-node and vite-plugin-commonjs-externals? Not sure if they can works
Hello, Using these two plug-ins still does not work
Then you have to find a substitute for aes-cross