【发布时间】:2017-07-08 14:46:42
【问题描述】:
每当我运行webpack-dev-server 时,它都会抛出这个错误:
....webpack/hot/only-dev-server ./src Module not found: Error: Can't resolve './src' in 'C:\....
这是 webpack.config.js 文件
var webpack = require('webpack');
var path = require('path');
module.exports = {
devtool: "inline-source-map",
entry: [
"webpack-dev-server/client?http://127.0.0.1:8080/",
"webpack/hot/only-dev-server",
"./src"
],
output: {
path: path.join(__dirname, 'public'),
filename: 'bundle.js'
},
resolve: {
modules: ['node_modules', 'src'],
extensions: ['.js']
},
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loaders: ['react-hot-loader','babel-core?presets[]=react,presets[]=es2015'],
}
]
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin()
],
};
包.json
{
"name": "react-todo",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"babel": "^6.23.0",
"babel-core": "^6.23.1",
"babel-loader": "^6.3.2",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-plugin-react-html-attrs": "^2.0.0",
"babel-plugin-transform-class-properties": "^6.23.0",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-preset-es2015": "^6.22.0",
"babel-preset-react": "^6.23.0",
"babel-preset-stage-0": "^6.22.0",
"lodash": "^4.17.4",
"react": "^15.4.2",
"react-dom": "^15.4.2",
"webpack": "^2.2.1",
"webpack-dev-server": "^2.3.0"
},
"devDependencies": {
"react-hot-loader": "^1.3.1"
}
}
我该如何解决?
【问题讨论】:
-
您的
src文件夹中有index.*吗?src文件夹是否存在?尝试将最后一个入口点设为文件而不是文件夹,例如./src到./src/index.js -
现在显示
cant resolve react-hot,更新了我的代码! -
你
npm install --save-dev react-hot-loader了吗? -
现在我做到了,再次更新代码!错误继续捆绑!现在抛出:
babel-core\index.js in not a loader must have normal or pitch function -
用
package.json的内容更新您的问题。你npm install --save-dev babel-core babel-loader babel-preset-es2015了吗?
标签: javascript webpack ecmascript-6 webpack-dev-server webpack-2