Skip to content

Argon2 not able to be repackaged #337

@bplies-ATX

Description

@bplies-ATX

Pretty much an identical situation as #261 with the same symptom and solution except that webpack is not involved. In this case argon2 is imported into a private library to handle multiple kinds of hashes. That library, in turn, is imported into other applications.

Similarity to #261

As with #261 replacing

const binary = require('node-pre-gyp')
const path = require('path')
const bindingPath = binary.find(path.resolve(path.join(__dirname, './package.json')))

const { hash: _hash, limits, types, names, version } = require(bindingPath) /* eslint-disable-line */

with

const { hash: _hash, limits, types, names, version } = require("argon2/lib/binding/napi-v3/argon2.node")

Fixes the issue.

Difference from #261

Unlike #261 webpack isn't involoved so adding

  externals: {
    "argon2": "argon2",
  },

to webpack.config.js isn't an option to fix the issue.

Possible Workarounds

Aside from an actual fix into this codebase...

  • Impose webpack where it isn't otherwise needed
  • Make a custom-patched version of argon2 with the code change we know works
  • Use the argon2-ffi library instead - which is less-frequently maintained and doesn't appear to support argon2id mode.

Steps to reproduce

  1. Create a module that imports argon2 without webpack
  2. Import that new module into an application without webpack
  3. Try running the application

Expected behaviour

It should presumably work.

Actual behaviour

Error: Cannot find module '/[....]/node_modules/argon2/package.json'
    at webpackEmptyContext (/[....]/packages/server/.webpack/service/dist/src/webpack:/[....]/node_modules/node-pre-gyp/lib sync:2:1)
    at Object.module.exports.../../node_modules/node-pre-gyp/lib/pre-binding.js.exports.find (/[....]/packages/server/.webpack/service/dist/src/webpack:/[....]/node_modules/node-pre-gyp/lib/pre-binding.js:20:23)
    at Object.<anonymous> (/[....]/packages/server/.webpack/service/dist/src/webpack:/[....]/node_modules/argon2/argon2.js:8:1)
    at Object.../../node_modules/argon2/argon2.js (/[....]/packages/server/.webpack/service/dist/src/serverless.js:31908:30)
    at __webpack_require__ (/[....]/packages/server/.webpack/service/dist/src/webpack:/webpack/bootstrap:19:1)

Environment

Operating system: OSX Catalina 10.15.7

Node version: 16.9.1

Compiler version:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions