Issue: In an Ionic-Angular application, argon2-browser modules are not being found

I am attempting to integrate argon2-browser into my Ionic-Angular project. Upon syncing with

ionic cap sync

I encounter the following errors:

./node_modules/argon2-browser/dist/argon2.js:35:22-45 - Error: Module not found: Error: Can't resolve 'path' in 'C:\Users\SomeUser\WebstormProjects\foo\project\node_modules\argon2-browser\dist'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }'
        - install 'path-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "path": false }

./node_modules/argon2-browser/dist/argon2.js:40:26-39 - Error: Module not found: Error: Can't resolve 'fs' in 'C:\Users\SomeUser\WebstormProjects\foo\project\node_modules\argon2-browser\dist'

./node_modules/argon2-browser/dist/argon2.wasm - Error: Module not found: Error: Can't resolve 'a' in 'C:\Users\SomeUser\WebstormProjects\foo\project\\node_modules\argon2-browser\dist'

This section contains the relevant code:

async generateHash() {
    const hash = await argon2.hash({pass: "testPassword", salt: "testSalt", type: 0})
      .then(h => console.log(h.hash, h.hashHex, h.encoded))
      .catch(e => console.error(e.message, e.code));
  }

And here is a snippet from my package.json:

"dependencies": {
...
 "@angular/cdk": "^15.2.9",
 "@angular/common": "^15.0.0",
 "@angular/core": "^15.0.0",
 "@angular/forms": "^15.0.0",
 "@angular/platform-browser": "^15.0.0",
 "@angular/platform-browser-dynamic": "^15.0.0",
 "@types/argon2-browser": "^1.18.1",
...
},
"devDependencies": {
 "@angular/cli": "^15.0.0",
 "@angular/compiler": "^15.0.0",
 "@angular/compiler-cli": "^15.0.0",
 "@angular/language-service": "^15.0.0",
 "@capacitor/cli": "^4.7.0",
 "@ionic/angular-toolkit": "^8.0.0",
 "@ionic/cli": "^6.20.9",
 "argon2-browser": "^1.18.0",
}

My troubleshooting attempts so far include:

  • Installing the missing modules

  • Adding the following configuration to my package.json:

 "browser":{
    "path": false,
    "fs": false,
    "a": false
  },

This stopped the error during syncing, but when running the code on my Android device, I encountered the following error:

Msg: WebAssembly.instantiate(): Import #0 module="a" function="a" error: function import requires a callable undefined

What could be the issue here?

Your assistance is much appreciated :)

Answer №1

After making the following adjustments, the problem was resolved successfully.

To address this issue, it is necessary to generate a customized webpack configuration using https://www.npmjs.com/package/@angular-builders/custom-webpack

  "dependencies": {
    ...
    "argon2-browser": "^1.18.0",
    "base64-loader": "^1.0.0",
    "path-browserify": "^1.0.1",
    "ts-loader": "^9.4.4",
    ...
  },
  "devDependencies": {
    ...
    "@types/argon2-browser": "^1.18.1",
    ...
  }

Incorporate these changes in your extra-webpack.config.js file:

module.exports = {
    resolve: {
        extensions: ['.webpack.js', '.web.js', '.js', '.ts'],
        fallback: {
            path: require.resolve("path-browserify"),
            fs: false,
            a: false
        }
    },
    mode: 'production',
    experiments: {
        asyncWebAssembly: true,
        syncWebAssembly: true
    },
    module: {
        rules: [
            {
                test: /\.wasm$/,
                loader: "base64-loader",
                type: 'javascript/auto'
            },
            {
                test: /\.ts$/,
                exclude: /node_modules/,
                use: 'ts-loader'
            }
        ]
    }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Building a TypeScript and Typings powered Express server

Struggling to configure an express web server with TypeScript, encountering a recurring error during the transpilation to JS error TS1008: Unexpected token; 'module, class, interface, enum, import or statement' expected. As a beginner, here&apo ...

What is the method for defining unassociated variables in Angular?

I am currently seeking a solution to retrieve data from the server (or JSON file) and store it in two separate variables: 'firstVariable' for manipulation purposes, and 'secondVariable' for storing the original unaltered data. However, ...

Exploring the capabilities of Angular 10 in conjunction with threex.domevents.js

I'm experiencing difficulties with incorporating threex into my Angular project. Does anyone have experience using this JavaScript library in an Angular environment? ...

What is the best way to limit the options for enum string values in typescript?

Regarding the type with possible value of action type PersistentAction = 'park' | 'retry' | 'skip' | 'stop' I would like to create an enum that corresponds to these actions enum PersistentActions { PARK = 'pa ...

The parameter type 'Object' cannot be assigned to the parameter type 'JSON' in the HttpClient GET method

Hey there! Currently, I'm deep into developing an Angular 6 + Flask application and I've encountered a bit of a snag: Error TS2345: Argument of type 'Object' is not assignable to parameter of type 'JSON'. This issue arises w ...

The functionality of MaterializeCSS modals seems to be experiencing issues within an Angular2 (webpack) application

My goal is to display modals with a modal-trigger without it automatically popping up during application initialization. However, every time I start my application, the modal pops up instantly. Below is the code snippet from my component .ts file: import ...

Utilizing Google Cloud Functions for automated binary responses

I need to send a binary response (image) using Google Cloud Functions. My attempted solution is: // .ts import {Request, Response} from "express"; export function sendGif(req: Request, res: Response) { res.contentType("image/gif"); res.send(new ...

Implementing ngClass change on click within an Angular component using Jasmine: A comprehensive guide

It seems like the click event is not triggering and the ngClass is not changing to active on the button I am attempting to click. -- HTML: <div class='btn-group' role='group' aria-label=""> <button type='button&apos ...

Deactivate a variable during operation

I have a unique component called book-smart that has the functionality to display either book-update or book-create based on the availability of a BookDto in my book.service. The update feature can be accessed by clicking a button in a table, while the cre ...

Creating a Circle with Pixi.js v4 and Typerscript in IONIC 2

I have been attempting to create a custom class in TypeScript that utilizes PIXI.js to draw circles. Below is the code for my home.ts class: import { Component, ViewChild, ElementRef } from '@angular/core'; import { NavController } from 'i ...

Trouble shooting: Angular 2 Http get request not firing

I'm facing an issue where nothing happens when I try to subscribe to my observable. There are no errors in the console or during the build process. Below is the code snippet that I am using: My service getBlueCollars(): Observable<BlueCollar[]& ...

Steps for creating a TypeScript project with React Native

Hey there, I'm just starting out with react-native and I want to work on a project using VS Code. I'm familiar with initializing a project using the command "react-native init ProjectName", but it seems to generate files with a .js extension inst ...

Navigate to a different directory within Cypress by utilizing the cy.exec() function

Dealing with cypress to execute a python script in another directory. However, it seems like the directory change is not functioning as expected. visitPythonProject() { cy.exec("cd /Users/**/Desktop/project/"); cy.exec("ls"); // thi ...

A guide on dynamically showcasing/summoning icons in react by utilizing array data

QUESTION: 1 (SOLVED!) https://i.stack.imgur.com/1M1K7.png What is the best way to display icons based on an array of data codes? const data = [{ img: '01d' }, { img: '02d' }] if(data) { data.map((item) => ( <img src={`./ ...

Exploring ways to display all filtered chips in Angular

As a new developer working on an existing codebase, my current task involves displaying all the chips inside a card when a specific chip is selected from the Chip List. However, I'm struggling to modify the code to achieve this functionality. Any help ...

What is the best way to transfer a variable between components in Angular without using the HTML page, directly within the components themselves?

Within the child component, I am working with a string: @Input() helloMessage:string; I am looking to assign a value to this string from another string in the parent component and utilize it within the child component without displaying the value in the h ...

"Encountering issues with NPM run build not working during Docker build process

Encountering an error while running docker build is causing frustration. Docker runs npm install -f, and changing it to npm install did not solve the problem. The lengthy logs cannot be posted here, but can be viewed in detail here. Here's a snippet o ...

Having trouble accessing the property 'prototype' of null in Bing Maps when using Angular4

I'm currently working on creating a Bing component in Angular 4, but I'm facing issues with rendering the map. Below is my index.html file: <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title> ...

The MdIcon in Angular 2 Material that functions properly in one component is causing issues in another

After upgrading from ng2 rc4 with material2 alpha6 to ng2 rc5 with material 2 alpha7-2, I encountered a new error related to the usage of <md-icon> which was previously working fine. The error message that appears now is Observable_1.Observable.thro ...

How can you adjust the size of focused elements like autocomplete or datepicker in Angular Material 15?

I recently updated to Material 15 and I'm wondering how I can adjust the height or overall size of focused components like autocomplete or datepicker. The page mentioned that density cannot be used on such components, so what other methods are availa ...