ERROR in ./node_modules/jsonwebtoken/sign.js 18:4–21
Module not found: Error: Can’t resolve ‘crypto’ in ‘/Users/bounphonekosada/Documents/course/vue-ts/node_modules/jsonwebtoken’
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback ‘resolve.fallback: { “crypto”: require.resolve(“crypto-browserify”) }’
- install ‘crypto-browserify’
If you don’t want to include a polyfill, you can use an empty module like this:
resolve.fallback: { “crypto”: false }
It seems like you are trying to use the jsonwebtoken
package in a Vue project with Webpack, but you're encountering an error because the crypto
module, which is a Node.js core module, is not found.
Webpack 5 no longer automatically includes polyfills for Node.js core modules. To fix this issue, you need to configure a polyfill for the crypto
module. Here's what you should do:
- Install the
crypto-browserify
package, which provides a browser-compatible version of thecrypto
module:
npm install --save crypto-browserify
- Update your webpack configuration file (usually
webpack.config.js
orvue.config.js
if you're using Vue CLI) to include a fallback for thecrypto
module. Add the following code to theresolve
object:
resolve: {
// ...
fallback: {
"crypto": require.resolve("crypto-browserify")
}
}
For example, if you’re using Vue CLI, your vue.config.js
file should look like this:
module.exports = {
configureWebpack: {
resolve: {
fallback: {
"crypto": require.resolve("crypto-browserify")
}
}
}
}
Save the changes, and then try running your application again. The issue should be resolved, and you should be able to use jsonwebtoken
in your project without any errors.