Skip to content

Argon2 does not work with webpack #261

@jayd-mh

Description

@jayd-mh

Steps to reproduce

  1. Install and include argon in your project
  2. run your application e.g. via nodemon - everything works fine
  3. run your application via serverless (after creating a webpack build) -> an error is thrown.

Expected behaviour

I'm having issues using argon2 in my project when building it with webpack and running it with serverless.
The following lines in the argon2.js file seem to be a problem for webpack (webpack cannot resolve dynamic imports/requires):

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 */

it is working if you change above lines to:

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

Any suggestions how to fix this? (is there anything I can do differently?)

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: MacOS - Catalina 10.15.5

Node version: v12.17.0
Webpack version:* 4.42.0

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions