【发布时间】:2016-03-28 03:53:26
【问题描述】:
我正在处理一个 React/Redux 项目,并且一直在努力让 superagent 工作。
在超级代理问题中关注问题并向我的 webpack.config 文件添加一些解决方法后,我能够构建我的包而没有错误。不幸的是,我现在在浏览器中遇到错误:
require is not defined
指向线路:module.exports = require("tty");
我相信 tty 是一个核心节点模块。此外,对 tty 的要求来自我对客户端的 require('superagent') 调用。
这是我的 webpack 配置:
var path = require('path')
var webpack = require('webpack')
var config = {
devtool: 'cheap-module-eval-source-map',
target: 'node',
entry: [
'webpack-hot-middleware/client',
'./client/index'
],
output: {
path: path.join(__dirname, 'dist'),
filename: 'bundle.js',
publicPath: '/static/'
},
plugins: [
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
new webpack.DefinePlugin(
{
'process.env.NODE_ENV': '"development"',
'global.GENTLY': false
}
),
],
module: {
loaders: [
{ test: /\.json$/, loaders: ['json'], },
{ test: /\.js$/, exlude: /node_modules/, loaders: ['babel', 'eslint'], },
]
},
// build breaks on eslint without this workaround
// https://github.com/MoOx/eslint-loader/issues/23
eslint: {
emitWarning: true
},
node: {
__dirname: true,
}
}
module.exports = config;
有人知道我的问题可能是什么吗?我搜索了 webpack 和 superagent 问题,这似乎是最相关的:https://github.com/facebook/react-native/issues/10
【问题讨论】:
标签: reactjs webpack redux superagent