Javascript 无法配置webpack.config文件

Javascript 无法配置webpack.config文件,javascript,webpack,ecmascript-6,webpack-dev-server,webpack-2,Javascript,Webpack,Ecmascript 6,Webpack Dev Server,Webpack 2,每当我运行webpack dev server时,它都会抛出以下错误: …webpack/hot/only dev server./src模块未找到:错误:无法解析'C:\..中的'/src'。 这是webpack.config.js文件 var webpack = require('webpack'); var path = require('path'); module.exports = { devtool: "inline-source-map", entry: [

每当我运行
webpack dev server
时,它都会抛出以下错误:

…webpack/hot/only dev server./src模块未找到:错误:无法解析'C:\..中的'/src'。

这是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()
    ],
};
Package.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"
  }
}

如何修复它?

您似乎正在使用Windows(
'C:\…'
在错误消息中),以及网页包Windows路径分隔符,如
\
,而不是
/
。你能试试
“\src\your\u entry\u file.js”
而不是
“/src”

试试这个:

将您的包json更新为:

{
  "name": "react-todo",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node server.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "lodash": "^4.17.4",
    "react": "^15.4.2",
    "react-dom": "^15.4.2"
  },
  "devDependencies": {
    "react-hot-loader": "^1.3.1",
    "webpack": "^2.2.1",
    "webpack-dev-server": "^2.3.0",
    "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",
  }
}
然后从项目文件夹的根目录运行
npm install

将您的
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/app.js" // or whatever your entry file is
    ],
    output: {
        path: path.join(__dirname, 'public'),
        filename: 'bundle.js'
    },
    resolve: {
        modules: ['node_modules', 'src'],
        extensions: ['.js']
    },
    module: {
        loaders: [
            {
                test: /\.js$/,
                exclude: /(node_modules|bower_components)/,
                loader: 'babel-loader',
                query: {
                    presets: ['es2015']
                }
            },
            // the loader should be broken up into two objects
            { test: /\.jsx?$/, loaders: ['react-hot', 'jsx?harmony'], include: path.join(__dirname, 'src') }
        ]
    },
    plugins: [
        new webpack.HotModuleReplacementPlugin(),
        new webpack.NoEmitOnErrorsPlugin()
    ],
};
下载
server.js
文件并将其保存到项目文件夹中

然后尝试
npm启动


希望这能奏效。祝你好运请参阅
src
文件夹中是否有
索引。*
src
文件夹是否存在?尝试将最后一个入口点设置为文件,而不是文件夹,例如
/src
/src/index.js
现在它显示
无法解析react hot
,更新了我的代码!您是否安装了npm?是否保存了dev react hot loader?现在我安装了,请再次更新代码!错误不断地堆积起来!现在抛出:
babel core\index.js在非加载器中必须具有正常或音调功能
使用您的
包.json的内容更新您的问题。您是否
npm安装--保存dev babel core babel loader babel-preset-es2015
?再次出错,请检查discussion@JaskaranSinghPuri哦,我忘了,请执行
npm安装--也保存dev express