javascript - webpack-dev-server配置之后报错
本文介绍了javascript - webpack-dev-server配置之后报错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>Getting Started</title>
</head>
<body>
<script src="bundle.js"></script>
</body>
</html>
webpack.config.js
var path = require('path');
module.exports = {
entry: './src/index.js',
devServer: {
contentBase: './dist'
},
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist')
}
};
index.js
import _ from 'lodash';
function component() {
var element = document.createElement('div');
// Lodash, now imported by this script
element.innerHTML = _.join(['Hello', 'webpack'], ' ');
return element;
}
document.body.appendChild(component());
package.json
{
"name": "day43",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "webpack-dev-server --open"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"webpack": "^3.3.0",
"webpack-dev-server": "^2.6.0"
},
"dependencies": {
"lodash": "^4.17.4"
}
}
配置如上所示,配置好后,运行npm start之后报错:
ERROR in (webpack)-dev-server/client?http://localhost:8080
Module not found: Error: Can't resolve 'loglevel' in '/Users/qinqinqin/Desktop/IFE-2017/day43/node_modules/webpack-dev-server/client'
@ (webpack)-dev-server/client?http://localhost:8080 4:10-29
@ multi (webpack)-dev-server/client?http://localhost:8080 ./src/index.js
不知道是什么原因,求大神指导,跪谢!
解决方案
谢谢各位大神的指教,我在自动编译之前配置babel以后,问题得以解决,虽然不知道是不是这个原因,但是确实是不报错了
这篇关于javascript - webpack-dev-server配置之后报错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文