Uncaught ReferenceError: process is not defined after upgrading from vue cli v4 to v5
Uncaught ReferenceError: process is not defined after upgrading from vue cli v4 to v5
我正在开发一个应用程序,我已将前端更新为使用 v4 中的 vue cli v5,但出现 运行时间错误:Uncaught ReferenceError: process is not defined . Process.version 在我使用的 jsonwebtoken 库中被引用。见下文:
Uncaught ReferenceError: process is not defined error
jsonwebtoken reference
由于 vue cli v5 使用 webpack 5,我在编译期间遇到了一些与 pollyfill 模块相关的错误,我在下面修复了这些错误:
fallback: {
crypto: require.resolve('crypto-browserify'),
buffer: require.resolve('buffer'),
util: require.resolve('util'),
stream: require.resolve('stream-browserify')
}
在我的 webpack 配置文件中,我尝试了 adding/setting process.env 变量:
module.exports = {
plugins: [
new webpack.DefinePlugin({
'process.env': ''
}),
new Dotenv({ systemvars: true })
],
有人 运行 在升级到 vue cli v5 时遇到过类似的问题吗?谢谢!
试试看:
const webpack = require('webpack');
const {defineConfig} = require('@vue/cli-service');
module.exports = defineConfig({
transpileDependencies: true,
configureWebpack: {
//process: {env: {}},
plugins: [
// fix "process is not defined" error:
// (do "npm install process" before running the build)
new webpack.ProvidePlugin({
process: 'process/browser',
}),
],
resolve: {
fallback: {
http: require.resolve("stream-http"),
https: require.resolve("https-browserify"),
crypto: require.resolve("crypto-browserify"),
stream: require.resolve("stream-browserify"),
os: require.resolve("os-browserify/browser"),
url: require.resolve("url"),
assert: require.resolve("assert"),
},
},
}
});
我正在开发一个应用程序,我已将前端更新为使用 v4 中的 vue cli v5,但出现 运行时间错误:Uncaught ReferenceError: process is not defined . Process.version 在我使用的 jsonwebtoken 库中被引用。见下文:
Uncaught ReferenceError: process is not defined error
jsonwebtoken reference
由于 vue cli v5 使用 webpack 5,我在编译期间遇到了一些与 pollyfill 模块相关的错误,我在下面修复了这些错误:
fallback: {
crypto: require.resolve('crypto-browserify'),
buffer: require.resolve('buffer'),
util: require.resolve('util'),
stream: require.resolve('stream-browserify')
}
在我的 webpack 配置文件中,我尝试了 adding/setting process.env 变量:
module.exports = {
plugins: [
new webpack.DefinePlugin({
'process.env': ''
}),
new Dotenv({ systemvars: true })
],
有人 运行 在升级到 vue cli v5 时遇到过类似的问题吗?谢谢!
试试看:
const webpack = require('webpack');
const {defineConfig} = require('@vue/cli-service');
module.exports = defineConfig({
transpileDependencies: true,
configureWebpack: {
//process: {env: {}},
plugins: [
// fix "process is not defined" error:
// (do "npm install process" before running the build)
new webpack.ProvidePlugin({
process: 'process/browser',
}),
],
resolve: {
fallback: {
http: require.resolve("stream-http"),
https: require.resolve("https-browserify"),
crypto: require.resolve("crypto-browserify"),
stream: require.resolve("stream-browserify"),
os: require.resolve("os-browserify/browser"),
url: require.resolve("url"),
assert: require.resolve("assert"),
},
},
}
});