lukus
lukus

Reputation: 1

Compile serialport module using babel and webpack

Im running an old version of electron (v6) and node v16 and I need to use the latest serialport (v11) module which contains a newer syntax like optional chaining etc. I am using both babel and webpack with the following configuration but the serialport module does not seem to compile for me. This is the config that I am currently using.

babel.config.js

    presets: [
      [
        require('@babel/preset-env'),
        {
          targets: {electron: require('electron/package.json').version},
          useBuiltIns: 'usage',
          corejs: 2
        }
      ]
    ]

webpack.config.js

    module: {
        target: 'electron-renderer'
        rules: [{
            test: /\.js$/,
            exclude: /node_modules\/(?!@serialport)/, 
            use: {
              loader: 'babel-loader',
              options: {
                presets: ['@babel/preset-env', '@babel/preset-react']
              }
            }
         }]
    }

Is there something that I am missing as I still get Unexpected token . on the following line return (this.port?.isOpen ?? false) && !this.closing

Ive tried various webpack and babel configurations and also researched possible version conflicts all of which I cant get to work.

Any help would be much appretiated

Upvotes: 0

Views: 79

Answers (0)

Related Questions