vite icon indicating copy to clipboard operation
vite copied to clipboard

TypeError: crypto.createCipheriv is not a function

Open LQS5858 opened this issue 4 years ago • 5 comments

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

LQS5858 avatar Dec 10 '21 04:12 LQS5858

It's not a bug. aes-cross depends on crypto, which is a node module and cannot be used in browsers.

ygj6 avatar Dec 10 '21 08:12 ygj6

It's not a bug. aes-cross depends on crypto, which is a node module and cannot be used in browsers.

Hello,Is there a solution in vite

LQS5858 avatar Dec 11 '21 02:12 LQS5858

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

ygj6 avatar Dec 11 '21 02:12 ygj6

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

LQS5858 avatar Dec 25 '21 08:12 LQS5858

Then you have to find a substitute for aes-cross

ygj6 avatar Dec 25 '21 08:12 ygj6