webpackを使用してexpress.jsアプリケーションを構築する際に問題が発生しています。私はnode.jsコアモジュール 'http'を正しく処理していないと思われます。webpackビルドでノードコアモジュールを正しく使用する
。具体的に:
{
"name": "basic-express-example",
"version": "1.0.0",
"description": "description here",
"main": "index.js",
"author": "",
"license": "ISC",
"scripts": {
"build": "webpack -d"
},
"dependencies": {
"babel-core": "^6.22.1",
"babel-loader": "^6.2.10",
"babel-preset-es2015": "^6.22.0",
"babel-preset-react": "^6.22.0",
"express": "^4.14.1",
"webpack": "^2.2.1"
}
}
マイwebpack.config.jsが
var webpack = require('webpack');
var path = require('path');
var BUILD_DIR = path.resolve(__dirname, 'build');
var APP_DIR = path.resolve(__dirname, 'app');
var config = {
entry: APP_DIR + '/index.jsx',
output: {
path: BUILD_DIR,
filename: 'index.js'
},
module : {
loaders : [
{
test : /\.jsx?/,
include : APP_DIR,
exclude : [
/node_modules/,
/build/
],
loader : 'babel-loader'
}
]
},
node: {
fs: 'empty',
net: 'empty'
}
};
module.exports = config;
ように私のアプリフォルダ内のファイルのみを検索しますように私のpackage.jsonが見えますindex.jsx:
今import express from 'express';
const app = express();
私はnpm build
を使用してアプリケーションを構築し、node build/index.js
を使用したファイルを実行しようとした場合、私はどのように私はこの問題を解決するのです
undefined:31
__proto__: http.IncomingMessage.prototype
^
TypeError: Cannot read property 'prototype' of undefined
を言うタイプのエラーを取得し、すなわちどのように私は作るのですかhttpモジュールを利用できますか?
事前にお問い合わせいただきありがとうございます。
var http = require( 'http'); in index.js – owaishanif786
@ owaishanif786 webpackを構築した結果、index.jsを直接変更することはできません。 index.jsxに追加しようとしましたが、私はまだ同じエラーが発生しています。 – user1993047