用webpack4时候出了的问题

#1
i 「wdm」: Compiled with warnings.
i 「wdm」: Compiling...
D:\gitproject\WebServer\node_modules\_html-webpack-plugin@3.2.0@html-webpack-plugin\lib\compiler.js:111
          content: childCompilation.assets[outputName].source()
                                                       ^

TypeError: Cannot read property 'source' of undefined
    at childCompiler.runAsChild (D:\gitproject\WebServer\node_modules\_html-webpack-plugin@3.2.0@html-webpack-plugin\lib\compiler.js:111:56)
    at compile (D:\gitproject\WebServer\node_modules\_webpack@4.6.0@webpack\lib\Compiler.js:242:11)
    at hooks.afterCompile.callAsync.err (D:\gitproject\WebServer\node_modules\_webpack@4.6.0@webpack\lib\Compiler.js:487:14)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (D:\gitproject\WebServer\node_modules\_tapable@1.0.0@tapable\lib\HookCodeFactory.js:24:12), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (D:\gitproject\WebServer\node_modules\_tapable@1.0.0@tapable\lib\Hook.js:35:21)
    at compilation.seal.err (D:\gitproject\WebServer\node_modules\_webpack@4.6.0@webpack\lib\Compiler.js:484:30)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (D:\gitproject\WebServer\node_modules\_tapable@1.0.0@tapable\lib\HookCodeFactory.js:24:12), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (D:\gitproject\WebServer\node_modules\_tapable@1.0.0@tapable\lib\Hook.js:35:21)
    at hooks.optimizeAssets.callAsync.err (D:\gitproject\WebServer\node_modules\_webpack@4.6.0@webpack\lib\Compilation.js:966:35)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (D:\gitproject\WebServer\node_modules\_tapable@1.0.0@tapable\lib\HookCodeFactory.js:24:12), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (D:\gitproject\WebServer\node_modules\_tapable@1.0.0@tapable\lib\Hook.js:35:21)
    at hooks.optimizeChunkAssets.callAsync.err (D:\gitproject\WebServer\node_modules\_webpack@4.6.0@webpack\lib\Compilation.js:957:32)
    at _err0 (eval at create (D:\gitproject\WebServer\node_modules\_tapable@1.0.0@tapable\lib\HookCodeFactory.js:24:12), <anonymous>:11:1)
    at D:\gitproject\WebServer\node_modules\_uglifyjs-webpack-plugin@1.2.5@uglifyjs-webpack-plugin\dist\index.js:334:11
    at _class.runTasks (D:\gitproject\WebServer\node_modules\_uglifyjs-webpack-plugin@1.2.5@uglifyjs-webpack-plugin\dist\uglify\index.js:63:9)
    at UglifyJsPlugin.optimizeFn (D:\gitproject\WebServer\node_modules\_uglifyjs-webpack-plugin@1.2.5@uglifyjs-webpack-plugin\dist\index.js:253:16)

D:\gitproject\WebServer>webpack-dev-server
#2

打包也不报错,执行webpack -w 和webpack-dev-server时候 只要一按保存 就会报这个错

#3

而且我发现上帝模式虽然执行了 但是没有帮我继续打包

#4

另外 贴一下 配置文件

var path = require('path');
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var CleanWebpackPlugin = require('clean-webpack-plugin');
/*var ExtractTextPlugin = require("extract-text-webpack-plugin");*/
var rootPath = __dirname + '/';
var config = {
    src:rootPath + 'src',
    dist:rootPath + 'public',
}
/*var extractLess = new ExtractTextPlugin({
    filename: "css/[name].[contenthash:8].css",
});
*/

var config = {
	devtool: 'false',
  context: path.resolve(__dirname, './src'),
  entry: {
  	'vendor': [
            'react',
            'react-redux',
            'react-dom',
            'redux',
            'react-router-dom',
            'redux-thunk'
           
        ],
    app:  config.src +'/index.js'
  },
   output: {
        path:config.dist,
        publicPath: '/',
        filename: 'js/[name].js',
        chunkFilename: "js/[name].js"
   },
  module: {
    rules: [
      {
        test: /\.(js|jsx)$/,
        exclude: /node_modules/,
        use:[{loader:"babel-loader"}]
      },
      {
         test: /\.css/,
           use: [
           	{
                  loader: "style-loader"
                }, {
                  loader: "css-loader",
                  options: {
                      modules: true, // 指定启用css modules
                      localIdentName: '[name]_[local]_[hash:base64:5]' // 指定css的类名格式
                      }
                  }
           ]
        
      },
      {
        test: /\.less$/,
        use: [{
                 loader: "style-loader" 
             }, {
                 loader: "css-loader" 
             }, {
                 loader: "less-loader" 
             }]
      },
      { 
         test: /\.(png|jpg)$/,
         loader: 'url-loader',
         options: {
           limit: 8129
         }
      }
    ]
  },
  devServer:{
      historyApiFallback: true,
      hot: true, //HMR模式   
      inline: true,//实时刷新
      port: 8181, // 修改端口,一般默认是8080
      contentBase:__dirname+"/src"
  },
  resolve: {
      extensions: ['.js', '.jsx', '.css'],
      modules: [path.resolve(__dirname, './src'), 'node_modules']
  },
  optimization: {
        runtimeChunk: {
            name: "manifest"
        },
        splitChunks: {
            cacheGroups: {
                vendor: {
                    test: /[\\/]node_modules[\\/]/,
                    name: "vendor",
                    priority: -20,
                    chunks: "all"
                }
            }
        }
   },
  plugins:[
  	new HtmlWebpackPlugin({
  		template:__dirname+"/src/index.html",
  		filename:__dirname+"/public/index.html"
  	}),
  	new webpack.HotModuleReplacementPlugin({
    multiStep:true,
  })
  ]
 

}
module.exports  = config;
#5

Markdown 大法了解一下 https://guides.github.com/features/mastering-markdown/

#6
#7

请问楼主解决了这个问题没有? 求解决办法!!!

#8

解决了 找了半天没找到 我就重新写了个 用着还不错 怀疑是插件版本的原因

#9
new webpack.HotModuleReplacementPlugin({
    multiStep:true,
  })

去掉这个就可以了,我的就是的

1 Like
#10

谢谢 之前看到了忘了感谢你了