G
G
Greg Orekhov2018-09-28 11:26:43
Node.js
Greg Orekhov, 2018-09-28 11:26:43

How to fix TypeError: Cannot read property 'emit' of undefined?

I try to start the server, but the application crashes with the following error:
/Users/orekhov.g/Documents/pantala/pantala-probe/node_modules/compression-webpack-plugin/dist/index.js:175
compiler.hooks.emit.tapAsync({ name: 'CompressionPlugin' }, emit);
^
TypeError: Cannot read property 'emit' of undefined
at CompressionPlugin.apply (/Users/orekhov.g/Documents/pantala/pantala-probe/node_modules/compression-webpack-plugin/dist/index.js:175:20)
at Compiler.apply (/Users/orekhov.g/Documents/pantala/pantala-probe/node_modules/tapable/lib/Tapable.js:375:16)
at webpack (/Users/orekhov.g/Documents/pantala/pantala-probe /node_modules/webpack/lib/webpack.js:33:19)
at Object. (/Users/orekhov.g/Documents/pantala/pantala-probe/server/index.js:19:22)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at loader (/Users /orekhov.g/Documents/pantala/pantala-probe/node_modules/babel-register/lib/node.js:144:5)
at Object.require.extensions.(anonymous function) [as .js] (/Users/orekhov .g/Documents/pantala/pantala-probe/node_modules/babel-register/lib/node.js:154:7)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal /modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Function.Module.runMain (internal/modules/cjs/loader.js :742:12)
at Object. (/Users/orekhov.g/Documents/pantala/pantala-probe/node_modules/babel-cli/lib/_babel-node.js:154:22)
at Module._compile (internal/modules/cjs/loader.js:689 :30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal /modules/cjs/loader.js:538:12)
[nodemon] app crashed - waiting for file changes before starting...
---------------------code webpack.config.dev.js-----------

var path = require('path')
var webpack = require('webpack')
var CompressionPlugin = require("compression-webpack-plugin")

module.exports = {
  entry: [
    'webpack-hot-middleware/client',
    path.join(__dirname, '/src/app.js')
  ],
  output: {
    path: path.resolve(__dirname, './dist'),
    publicPath: '/dist/',
    filename: 'build.js'
  },
  module: {
    rules: [
      {
        test: /\.vue$/,
        loader: 'vue-loader',
        options: {
          loaders: {
          }
          // other vue-loader options go here
        }
      },
      { 
        test: /\.js$/,
        loader: 'babel-loader',        
        exclude: /node_modules/
      },
      {
        test: /\.json$/,
        loader: 'json-loader'
      },
      {
        test: /\.(png|jpg|gif|svg)$/,
        loader: 'file-loader',
        options: {
          limit: 10000,
          name: '[name].[ext]?[hash]'          
        }
      }     
    ]
  },
  resolve: {
    alias: {
      'vue$': 'vue/dist/vue.esm.js'
    }
  },
  performance: {
    hints: false
  },
  devtool: '#eval-source-map',
  plugins: [
    new webpack.NoEmitOnErrorsPlugin(),
    new webpack.optimize.OccurrenceOrderPlugin(),
    new webpack.HotModuleReplacementPlugin(),
    new webpack.optimize.UglifyJsPlugin({
      beautify: false,
      comments: false,
      compress: {
        sequences : true,
        booleans : true,
        loops : true,
        unused : true,
        warnings : false,
        drop_console: true,
        unsafe : true
      }
    }),
    new CompressionPlugin({
      filename: '[path].gz[query]',
      algorithm: 'gzip',
      test: /\.(js|css|html|svg|png)$/,
      threshold: 10240,
      minRatio: 0.8
    })
  ]
}

---------------package.json---------------
{
  "name": "*******",
  "description": "A Vue.js project",
  "version": "1.0.0",
  "author": "**********",
  "license": "MIT",
  "private": true,
  "scripts": {
    "heroku-postbuild": "npm run build",
    "dev": "cross-env NODE-ENV=development PORT=5000 nodemon --config nodemon.json --watch server --exec babel-node server/index.js",
    "start": "cross-env PORT=5000 & babel-node server/index.js",
    "build": "webpack --progress --hide-modules"
  },
  "dependencies": {
    "axios": "^0.18.0",
    "body-parser": "^1.18.3",
    "compression-webpack-plugin": "^2.0.0",
    "connect-history-api-fallback": "^1.5.0",
    "express": "^4.16.3",
    "stylus": "^0.54.5",
    "vue": "^2.5.17"
  },
  "browserslist": [
    "> 1%",
    "last 2 versions",
    "not ie <= 8"
  ],
  "devDependencies": {
    "babel-cli": "^6.26.0",
    "babel-core": "^6.26.0",
    "babel-loader": "^7.1.2",
    "babel-preset-env": "^1.6.0",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-stage-0": "^6.24.1",
    "babel-preset-stage-3": "^6.24.1",
    "cross-env": "^5.2.0",
    "css-loader": "^0.28.7",
    "file-loader": "^1.1.4",
    "nodemon": "^1.18.4",
    "stylus-loader": "^3.0.2",
    "vue-loader": "^13.0.5",
    "vue-template-compiler": "^2.4.4",
    "webpack": "^3.6.0",
    "webpack-dev-middleware": "^3.4.0",
    "webpack-dev-server": "^2.9.1",
    "webpack-hot-middleware": "^2.24.2"
  }
}

 Kick me in the right direction. Thank you.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question