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

[v6] webpack: keytar native module has hardcoded path #1029

Closed
3 tasks done
louis-bompart opened this issue Jul 15, 2019 · 12 comments
Closed
3 tasks done

[v6] webpack: keytar native module has hardcoded path #1029

louis-bompart opened this issue Jul 15, 2019 · 12 comments
Labels
plugin/webpack Issues or pull requests related to first-party webpack plugins/templates

Comments

@louis-bompart
Copy link

louis-bompart commented Jul 15, 2019

  • I have read the contribution documentation for this project.
  • I agree to follow the code of conduct that this project follows, as appropriate.
  • 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.

@malept
Copy link
Member

malept commented Jul 16, 2019

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?

@louis-bompart
Copy link
Author

louis-bompart commented Jul 16, 2019 via email

@malept
Copy link
Member

malept commented Jul 16, 2019

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.

@louis-bompart
Copy link
Author

louis-bompart commented Jul 16, 2019 via email

@louis-bompart
Copy link
Author

louis-bompart commented Jul 16, 2019

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

@malept malept changed the title [v6] Webpack template, absolute path on native-module [v6] webpack: keytar native module has hardcoded path Jul 16, 2019
@malept
Copy link
Member

malept commented Jul 17, 2019

@malept malept mentioned this issue Jul 18, 2019
22 tasks
@pd4d10
Copy link
Contributor

pd4d10 commented Nov 1, 2019

+1

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

@conorgriffin
Copy link

conorgriffin commented Dec 3, 2019

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

@shezuka-monkey
Copy link

shezuka-monkey commented Dec 9, 2019

+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

@shezuka-monkey
Copy link

shezuka-monkey commented Dec 9, 2019

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 }

@malept malept added the plugin/webpack Issues or pull requests related to first-party webpack plugins/templates label Jan 23, 2020
@ThomasSzabo
Copy link

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',
      },
    },
  },
];

@malept
Copy link
Member

malept commented Oct 1, 2021

keytar works fine for me with the webpack template, Electron Forge v6 beta 61 and keytar 7.7.0 on Linux (which uses Node-API and prebuild-install).

create-electron-app --template=webpack keytar-app
cd keytar-app
yarn add keytar

Add to the top of src/main.js:

const keytar = require('keytar');
keytar.findPassword('nonexistentservice').then(result => console.log('KEYTAR RESULT', result));

Then run yarn start. The console.log statement will get run somewhere around the webpack-dev-server output.

@malept malept closed this as completed Oct 1, 2021
dsanders11 pushed a commit that referenced this issue Jan 14, 2023
Bumps [actions/setup-node](https://github.com/actions/setup-node) from 2.5.1 to 3.1.0.
- [Release notes](https://github.com/actions/setup-node/releases)
- [Commits](actions/setup-node@v2.5.1...v3.1.0)

---
updated-dependencies:
- dependency-name: actions/setup-node
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin/webpack Issues or pull requests related to first-party webpack plugins/templates
Projects
None yet
Development

No branches or pull requests

6 participants