gpt4 book ai didi

javascript - Webpack:Bundle.js - 未捕获的 ReferenceError:未定义进程

转载 作者:数据小太阳 更新时间:2023-10-29 05:14:29 25 4
gpt4 key购买 nike

这是我的 webpack.config.js

"use strict";

module.exports = {
entry: ['./main.js'],
output: { path: __dirname, filename: 'bundle.js' },
module: {
loaders: [
{
test: /.js?$/,
loader: 'babel-loader',
exclude: /node_modules/,
query: {
presets: ['es2015', 'react']
}
},
{test: /\.json$/, loader: "json"},
]
},
externals: {
React: 'react',
},
target: "node",
};

Main.js

import React from 'react';
import ReactDOM from 'react-dom';
import {Table, Column, Cell} from 'fixed-data-table';
import Chart from 'chartjs';
import jQuery from 'jquery';
import vis from 'vis';
import babel from 'babel-core';

Bundle.js 被插入到我的 Index.html 中。然后浏览器报错:

Uncaught ReferenceError: process is not defined
at Object.measureMethods (bundle.js:1297)
at Object.<anonymous> (bundle.js:530)
at __webpack_require__ (bundle.js:20)
at Object.<anonymous> (bundle.js:288)
at __webpack_require__ (bundle.js:20)
at Object.<anonymous> (bundle.js:158)
at __webpack_require__ (bundle.js:20)
at Object.<anonymous> (bundle.js:110)
at __webpack_require__ (bundle.js:20)
at Object.<anonymous> (bundle.js:90)

我应该在 webpack.config.js 中更改什么以使此错误消失?

最佳答案

2020 年 10 月更新:

对于 webpack 5,您可以从 webpack.config.js

的相应 plugins 部分引用 process/browser
// webpack needs to be explicitly required
const webpack = require('webpack')

module.exports = {

/* ... rest of the config here ... */

plugins: [
// fix "process is not defined" error:
// (do "npm install process" before running the build)
new webpack.ProvidePlugin({
process: 'process/browser',
}),
]
}

关于javascript - Webpack:Bundle.js - 未捕获的 ReferenceError:未定义进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41359504/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com