Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webpack / Babel fails to bundle due to the weird require in index.js #1224

Open
chriswiggins opened this issue Apr 29, 2022 · 0 comments
Open

Comments

@chriswiggins
Copy link

chriswiggins commented Apr 29, 2022

Expected Behavior

We are trying to bundle balena-sdk into an internal electron app we are writing. I'd expect Webpack and Babel to bundle these without any issues (like they do the rest of our dependency tree)

import { getSDK } from 'balena-sdk'

Actual Behavior

The bundling fails when the balena-sdk and pinejs-client-core package.json files point to index.js, as the @balena/es-version module somehow gets in the way of webpack, which then tries to load the .d.ts, .map and .md files (even though they're ignored)

This can be worked around by providing aliases to the 2018 versions in the webpack config file:

  resolve: {
    alias: {
      'balena-sdk': resolve(__dirname, '..', 'node_modules', 'balena-sdk', 'es2018'),
      'pinejs-client-core': resolve(__dirname, '..', 'node_modules', 'pinejs-client-core', 'es2018'),
    }
  }

Note that this also fails when trying to include the 2018 version of the balena-sdk, as then you hit issues downstream in pinejs-client-core:

import { getSDK } from 'balena-sdk/es2018'

Steps to Reproduce the Problem

  1. Bundle with webpack and babel-loader
  2. Hit issue

Specifications

  • SDK version: 16.19.8
  • Node version: v16.13.0
  • Npm version: 8.5.5
  • OS: macOS 12.1
  • Webpack: 5.72.2
  • babel-loader: 8.2.5

References

There's nothing special about our webpack file - this is just bundling the SDK into the Node.js side of electron:

'use strict';

const { resolve } = require('path');

/**
 *
 */
module.exports = {
  entry: resolve(__dirname, '..', 'src', 'main', 'main.ts'),

  module: {
    rules: [
      {
        test: /\.(j|t)sx?$/,
        exclude: /node_modules/,
        include: resolve(__dirname, '..', 'src'),
        use: [
          {
            loader: require.resolve('babel-loader'),
            options: {
              presets: [
                require.resolve('@babel/preset-typescript'),
                require.resolve('@babel/preset-env')
              ],
              targets: {
                electron: '16'
              }
            }
          }
        ]
      }
    ]
  },

  output: {
    chunkFilename: 'main-[id].js',
    filename: 'main.js',
    path: resolve(__dirname, '..', 'build')
  },

  plugins: [],

  resolve: {
    extensions: ['.js', '.ts']
  },

  target: 'electron-main'
};

Happy to test whatever required on my side

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant