Open bayramorhan opened 3 years ago
I also met this problem, how should I solve it?
I ran into a similar kind of problem with react + vite. Solved with the following vite.config.js
:
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
react()
],
resolve: {
alias: {
"crypto": "crypto-js"
}
}
})
Edit: This worked for local development, but it caused problems during production build. In the end i needed to upgrade the dependency that was causing the problem (aws-sdk-js
v2 -> v3)
Commenting out in core.js 40. fixing the issue ([vite] Dep optimization failed with error: Could not load crypto (imported by node_modules/crypto-js/core.js): ENOENT: no such file or directory, open 'crypto')
// Native crypto import via require (NodeJS) // if (!crypto && typeof require === 'function') { // try { // crypto = require('crypto'); // } catch (err) {} // }