1
我在嘗試使用webpack的第一步時偶然發現了這個錯誤。Webpack/Node.js Http模塊:http.createServer不是函數
只是爲了再現以非常基本的水平的影響,我設置此微文件夾是這樣的:
節點試驗-2
- main.js
- 的package.json
- webpack.config.js
具有以下內容:
的package.json
{
"name": "node-test-2",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "webpack && node bundle.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"webpack": "^2.2.0"
}
}
webpack.config.js
var path = require('path');
module.exports = {
entry : './main.js',
output : {
path : path.resolve(__dirname),
filename : 'bundle.js'
}
}
main.js
var http = require('http');
console.log("Creating Server");
var server = http.createServer(function(req, res){
console.log('Connection Estabilished!');
res.write('HELLO!');
res.end();
});
console.log("Listening on port " + 8000);
server.listen(8000);
現在,如果我只是node main.js
一切按預期工作。相反,如果我npm start
,因此提示webpack捆綁bundles.js需要的所有東西,然後運行它,運行時會顯示錯誤http.createServer is not a function
錯誤。
進一步檢查顯示該函數似乎根本沒有在bundle.js文件中聲明。
我在這裏錯過了什麼?這是什麼webpack實際上不是爲了?
更多,也許毫無意義,資訊:
- 運行在Windows 10
- 測試與節點版本6.9和7.10
- 當時既的WebPack和的WebPack @進行beta測試寫