shama / webpack-stream

:tropical_drink: Run webpack through a stream interface
MIT License
1.4k stars 123 forks source link

Cannot read property 'tapAsync' of undefined #203

Closed kamikyo closed 6 years ago

kamikyo commented 6 years ago

I found this issue. But it didn't solve my problem. #180

I still get this error:

D:\work\kefu\front\node_modules\webpack-stream\index.js:198
        ? function (callback) { compiler.hooks.afterEmit.tapAsync('WebpackStream', callback); }
                                                         ^

TypeError: Cannot read property 'tapAsync' of undefined
    at D:\work\kefu\front\node_modules\webpack-stream\index.js:198:58
    at handleCompiler (D:\work\kefu\front\node_modules\webpack-stream\index.js:202:7)
    at Stream.<anonymous> (D:\work\kefu\front\node_modules\webpack-stream\index.js:218:7)
    at _end (D:\work\kefu\front\node_modules\through\index.js:65:9)
    at Stream.stream.end (D:\work\kefu\front\node_modules\through\index.js:74:5)
    at DestroyableTransform.onend (D:\work\kefu\front\node_modules\vinyl-fs\node_modules\readable-stream\lib\_stream_readable.js:523:10)
    at Object.onceWrapper (events.js:313:30)
    at emitNone (events.js:111:20)
    at DestroyableTransform.emit (events.js:208:7)
    at D:\work\kefu\front\node_modules\vinyl-fs\node_modules\readable-stream\lib\_stream_readable.js:965:16
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickCallback (internal/process/next_tick.js:180:9)

package.json:

"devDependencies": {
    "@babel/core": "^7.0.0",
    "babel-loader": "^8.0.2",
    "copy-webpack-plugin": "^4.5.2",
    "css-loader": "^1.0.0",
    "expose-loader": "^0.7.5",
    "extract-text-webpack-plugin": "^4.0.0-beta.0",
    "file-loader": "^2.0.0",
    "gulp": "^3.9.1",
    "style-loader": "^0.23.0",
    "url-loader": "^1.1.1",
    "webpack": "^4.17.2",
    "webpack-cli": "^3.1.0",
    "webpack-stream": "^5.1.1"
  },
  "dependencies": {
    "jquery": "^3.3.1"
  }

webpack.config.js:

var path = require('path');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
var CopyWebpackPlugin = require('copy-webpack-plugin');

module.exports = [
    {

        resolve: {
            extensions: ['.js', '.json']
        },
        module: {
            rules: [
                {
                    test: require.resolve('jquery'),
                    use: [
                        {
                            loader: 'expose-loader',
                            options: '$'
                        },
                        {
                            loader: 'expose-loader',
                            options: 'jQuery'
                        }
                    ]
                },
                {
                    test: /\.js/, use: [{
                        loader: 'babel-loader'
                    }], exclude: /node_modules/
                },
                {
                    test: /\.css$/, use: ExtractTextPlugin.extract({
                        fallback: "style-loader",
                        use: {
                            loader: "css-loader",
                            options: {
                                sourceMap: true
                            }
                        }
                    })
                },
                {
                    test: /\.(png|jpg|gif)$/,
                    use: 'url-loader?limit=8192&name=[name].[ext]&publicPath=../&outputPath=images/'
                }
                , {
                    test: /\.(woff|woff2)(\?v=\d+\.\d+\.\d+)?$/,
                    use: 'url-loader?limit=8192&mimetype=application/font-woff&name=[name].[ext]&publicPath=../&outputPath=fonts/'
                }
                , {
                    test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/,
                    use: 'url-loader?limit=8192&mimetype=application/octet-stream&name=[name].[ext]&publicPath=../&outputPath=fonts/'
                }
                , {
                    test: /\.eot(\?v=\d+\.\d+\.\d+)?$/,
                    use: 'file-loader?name=[name].[ext]&publicPath=../&outputPath=fonts/'
                }
                , {
                    test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
                    use: 'url-loader?limit=8192&mimetype=image/svg+xml&name=[name].[ext]&publicPath=../&outputPath=fonts/'
                }
            ]
        },

        plugins: [
            new ExtractTextPlugin('[name].style.css', { allChunks: true }),
            new CopyWebpackPlugin([
                { from: path.resolve(__dirname, 'src/media'), to: path.resolve(__dirname, 'dist/media') },
            ])
        ],
        devtool: 'source-map'
    }
];

gulpfile.js:

var gulp = require('gulp');
var webpack = require('webpack-stream');
var webpackConfig = require("./webpack.config.js");

gulp.task('webpacktest', function () {
    gulp.src('./src/js/index.js')
        //.pipe(webpack(webpackConfig, require('webpack')))
        .pipe(webpack(webpackConfig))
        .pipe(gulp.dest('./dist'));
});
kamikyo commented 6 years ago

I found out where the problem occurred. webpack.config.js export Array,but pipe(webpack(webpackConfig)) only accept object