Electron-forge: [v6] webpack: keytar native module has hardcoded path

Created on 15 Jul 2019  ·  11Comments  ·  Source: electron-userland/electron-forge

  • [x] I have read the contribution documentation for this project.
  • [x] I agree to follow the code of conduct that this project follows, as appropriate.
  • [x] I have searched the issue tracker for an issue that matches the one I want to file, without success.

Using the default webpack template, my node native are loaded somewhat like this, using absolute path:

function(e, t, a) {
    (function (e) {
        try {
            global.process.dlopen(e, "D:\\path\\to\my\\repo\\node_modules\\keytar\\build\\Release\\keytar.node")
        } catch (e) {
            throw new Error("Cannot open D:\\path\\to\my\\repo\\node_modules\\keytar\\build\\Release\\keytar.node: " + e)
        }
    }
    ).call(this, a(61)(e))
}

Obviously, it works fine till I blast my node_module folder to oblivion, but as soon as I do, or -more importantly- try to distribute my app, it doesn't work.

webpack

Most helpful comment

Thanks @shezuka-monkey!! That fixed it for me:

Before
_webpack.rules.js_

module.exports = [
  // Add support for native node modules
  {
    test: /\.node$/,
    use: 'node-loader',
  },
  {
    test: /\.(m?js|node)$/,
    parser: { amd: false },
    use: {
      loader: '@marshallofsound/webpack-asset-relocator-loader',
      options: {
        outputAssetBase: 'native_modules',
      },
    },
  },
];

After
_webpack.rules.js_

module.exports = [
  // Add support for native node modules
  {
    test: /\.(m?js|node)$/,
    parser: { amd: false },
    use: {
      loader: '@marshallofsound/webpack-asset-relocator-loader',
      options: {
        outputAssetBase: 'native_modules',
      },
    },
  },
];

All 11 comments

In order to debug your problem further, we need a minimal testcase to reproduce your problem. Using create-electron-app --template=webpack as a base, could you please create a minimal Electron app that illustrates the issue you described, and post a link to it here?

Sure, will do, I'll try to provide you with that in the next few days.

On Mon., Jul. 15, 2019, 8:11 p.m. Mark Lee, notifications@github.com
wrote:

In order to debug your problem further, we need a minimal testcase to
reproduce your problem. Using create-electron-app --template=webpack as a
base, could you please create a minimal Electron app that illustrates the
issue you described, and post a link to it here?


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/electron-userland/electron-forge/issues/1029?email_source=notifications&email_token=AC6LESUMFRUAP5KW2N4LFL3P7UG3TA5CNFSM4IDTT4VKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZ7J5CY#issuecomment-511614603,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AC6LESVA4PRHHZCLDZ5N7LDP7UG3TANCNFSM4IDTT4VA
.

With the details currently provided, I cannot reproduce the behavior by simply adding the ref native module to a Forge v6 project using Webpack and utilizing it in the main process.

I'll try to reproduce the issue with a minimum reproducible case, maybe
it's only related to keytar specifically, I'll try to look into it asap

On Mon., Jul. 15, 2019, 8:21 p.m. Mark Lee, notifications@github.com
wrote:

With the details currently provided, I cannot reproduce the behavior by
simply adding the ref native module to a Forge v6 project using Webpack.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/electron-userland/electron-forge/issues/1029?email_source=notifications&email_token=AC6LESWC37PXKRQOGSJ7Z4LP7UIBDA5CNFSM4IDTT4VKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZ7KL2I#issuecomment-511616489,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AC6LESQOENRGND7UCUO4S4DP7UIBDANCNFSM4IDTT4VA
.

Here's a MRC. What I did:

  • create-electron-app --template=webpack

    • yarn add ref keytar

    • Modified the main.js to add some shenanigans with those two native modules.

    • Built with both, noticed the path issue I mentioned is here (just in case, I'm on Windows10)

    • Try to execute the package: it works

    • Wipe node_modules, the execution fails (same if reinstall).

    • yarn install

    • Removed keytar altogether only keep ref (commented line 2 and 12 of main.js)

    • Build and notice this strange path : process.resourcesPath+"/"+(-1===__filename.indexOf(".asar")?"app":"app.asar")+"/.webpack/main/native_modules//build/Release/binding.node" Note the double /

    • Execute. Fail, not matching node_modules (easy guess there: npm run make seems to skip the preparing native dependencie)

    • Run npm start

    • Works fine

    • Re make it works (my guess is because npm start packed it this time)

    • Rerun works fine er.

    • Wipe node_modules

    • Still works

After noticing the issue with the prepare native dep on the make step, I tested this:

  • put back keytar
  • npm start
  • npm run make
  • Try to run : ✔️
  • Wipe node_module
  • Try to run: initial error of the post Cannot open D:\\path\\to\my\\repo\\node_modules\\keytar\\build\\Release\\keytar.node:

I noticed that ref.node does not get into the native_modules folder, but keytar.node as well as bindings.node, for what's it worth.

It seems odd to me that keytar is the only native node module impacted, I'll try to reproduce with another

@MarshallOfSound does this have something to do with https://github.com/marshallofsound/webpack-asset-relocator-loader ?

+1

Seems webpack-asset-relocator-loader we are using does not handle it correctly.

Did anyone figure this out? I'm having a similar issue with keytar where everything works until I try to package and run the app on another machine. The binary still points to keytar on the development machine where it was built

+1

The same error as described above
App contains absolute path to keytar of machine that packaged it

OS: Windows
Build using electron-forge and squirrel.windows

Got it work
Changes that I made:

  1. Update package @zeit/webpack-asset-relocator-loader version from 0.5.0 to 0.6.2
  2. Changed main config:
module.exports = {
  entry: './src/index.js',

  module: {
    rules: [
      {
        test: /\.(m?js|node)$/,
        parser: { amd: false },
        use: {
          loader: '@zeit/webpack-asset-relocator-loader',
          options: {
            outputAssetBase: 'assets'
          },
        },
      },
    ]
  }
};

There was module node-loader
And property node: { __dirname: true }

Thanks @shezuka-monkey!! That fixed it for me:

Before
_webpack.rules.js_

module.exports = [
  // Add support for native node modules
  {
    test: /\.node$/,
    use: 'node-loader',
  },
  {
    test: /\.(m?js|node)$/,
    parser: { amd: false },
    use: {
      loader: '@marshallofsound/webpack-asset-relocator-loader',
      options: {
        outputAssetBase: 'native_modules',
      },
    },
  },
];

After
_webpack.rules.js_

module.exports = [
  // Add support for native node modules
  {
    test: /\.(m?js|node)$/,
    parser: { amd: false },
    use: {
      loader: '@marshallofsound/webpack-asset-relocator-loader',
      options: {
        outputAssetBase: 'native_modules',
      },
    },
  },
];
Was this page helpful?
0 / 5 - 0 ratings