Webpack errors with ssh2 package issue when upgrading from 0.8.9

Viewed 27

I've recently picked up an Electron legacy project and I'm having issues with the ssh2 package https://www.npmjs.com/package/ssh2. From what I can see the project is quite outdated but for now I'm just trying to do the minimum to clear some security vulnerabilities discovered.

The one package I'm having issues with is ssh2. This project is using webpack albeit an old version but it's working just fine up to the point of upgrading ssh2.

During running my app in my dev env I'm getting webpack parsing errors, when I check out the syntax error it's referring to its pointing at an empty catch block. An example would be:

 ERROR in ./~/ssh2/lib/server.js
 Module parse failed: C:\Users\<my local path>\node_modules\ssh2\lib\server.js Unexpected token (484:16)
 You may need an appropriate loader to handle this file type.
 SyntaxError: Unexpected token (484:16)
     at Parser.pp$4.raise (C:\Users\<my local path>\node_modules\webpack\node_modules\acorn\dist\acorn.js:2221:15)
     at Parser.pp.unexpected (C:\Users\<my local path>\node_modules\webpack\node_modules\acorn\dist\acorn.js:603:10)
     at Parser.pp.expect (C:\Users\<my local path>\node_modules\webpack\node_modules\acorn\dist\acorn.js:597:28)
     at Parser.pp$1.parseTryStatement (C:\Users\<my local path>\node_modules\webpack\node_modules\acorn\dist\acorn.js:902:12)
     at Parser.pp$1.parseStatement (C:\Users\<my local path>\node_modules\webpack\node_modules\acorn\dist\acorn.js:702:31)
     at Parser.pp$1.parseBlock (C:\Users\<my local path>\node_modules\webpack\node_modules\acorn\dist\acorn.js:981:25)
     at Parser.pp$3.parseFunctionBody (C:\Users\<my local path>\node_modules\webpack\node_modules\acorn\dist\acorn.js:2105:24)
     at Parser.pp$3.parseArrowExpression (C:\Users\<my local path>\node_modules\webpack\node_modules\acorn\dist\acorn.js:2087:10)
     at Parser.pp$3.parseParenArrowList (C:\Users\<my local path>\node_modules\webpack\node_modules\acorn\dist\acorn.js:1902:17)
     at Parser.pp$3.parseParenAndDistinguishExpression (C:\Users\<my local path>\node_modules\webpack\node_modules\acorn\dist\acorn.js:1870:21)
  @ ./~/ssh2/lib/index.js 33:10-32

And that is referring to this code:

  onError: (err) => {
    if (!proto._destruct)
      socket.removeAllListeners('data');
    this.emit('error', err);
    try {
      socket.end();
    } catch {} << // Error is throw here
  },

This is my webpack base config:

import path from 'path';
import WebpackNotifierPlugin  from 'webpack-notifier';

export default {
  module: {
    loaders: [{
      test: /\.jsx?$/,
      loaders: ['babel-loader'],
      exclude: /node_modules/
    }, {
      test: /\.json$/,
      loader: 'json-loader'
    }, {
        test: /\.cjs?$/,
        loaders: ['babel-loader']
      }
    ]
  },
  output: {
    path: path.join(__dirname, 'dist'),
    filename: 'bundle.js',
    libraryTarget: 'commonjs2'
  },
  resolve: {
    extensions: ['', '.js', '.jsx', '.json', '.cjs'],
    packageMains: ['webpack', 'browser', 'web', 'browserify', ['jam', 'main'], 'main']
  },
  plugins: [
    new WebpackNotifierPlugin({excludeWarnings: true}),
  ],
  externals: [
  ]
};

This is my webpack config for dev env:

/* eslint max-len: 0 */
import webpack from 'webpack';
import baseConfig from './webpack.config.base';

const config = {
  ...baseConfig,

  debug: true,

  devtool: 'cheap-module-eval-source-map',

  entry: [
    'webpack-hot-middleware/client?path=http://localhost:3000/__webpack_hmr',
    'babel-polyfill',
    './app/index'
  ],

  output: {
    ...baseConfig.output,
    publicPath: 'http://localhost:3000/dist/'
  },

  module: {
    ...baseConfig.module,
    loaders: [
      ...baseConfig.module.loaders,

      {
        test: /\.global\.css$/,
        loaders: [
          'style-loader',
          'css-loader?sourceMap'
        ]
      },

      {
        test: /^((?!\.global).)*\.css$/,
        loaders: [
          'style-loader',
          'css-loader?modules&sourceMap&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]'
        ]
      }
    ]
  },

  plugins: [
    ...baseConfig.plugins,
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NoErrorsPlugin(),
    new webpack.DefinePlugin({
      'process.env.NODE_ENV': JSON.stringify('development')
    })
  ],

  target: 'electron-renderer'
};

export default config;

Please for give me if this issue is obvious. I've done some webpack work a long time ago and may be forgetting something fundamental. The issue only happens when I upgrade to any version of ssh2 client greater than 0.8.9.

Any help or pointers at all would be great and much appreciated.

0 Answers
Related