【发布时间】:2017-05-12 14:04:38
【问题描述】:
这是我的 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 中进行哪些更改以消除此错误?
【问题讨论】:
-
对于我的打字稿项目,我添加了具有以下内容的 .d.ts 文件:“declare var process: any;”
-
你能解释一下你是如何在这里实现的吗?在 webpack 配置中..?
-
不在 webpack 配置中。在任何顶级文件中并定义为全局。它由转译处理并声明为全局。现在可以在前面使用“过程”。使用下方的DefinePlugin
标签: javascript node.js webpack node-modules