macaroons.js icon indicating copy to clipboard operation
macaroons.js copied to clipboard

Getting Module Not Found with Angular 6

Open anthonyikeda opened this issue 7 years ago • 2 comments

I've added the module to my project: yarn add macaroons.js

And the module gets added and I can use it in my Components:

import { MacaroonsBuilder } from 'macaroons.js';
...
    let macaroon = MacaroonsBuilder.create('http://localhost:4200', 'apples', 'working-ui');

But when I go to build the project I get

ERROR in ./node_modules/macaroons.js/lib/CryptoTools.js
Module not found: Error: Can't resolve 'crypto' in '\node_modules\macaroons.js\lib'

I've tried patching with the following approach: https://github.com/angular/angular-cli/issues/1548#issuecomment-386871992

But so far no luck.

$ ng -version
Angular CLI: 6.0.8
Node: 10.4.1
OS: win32 x64
Angular: 6.0.5
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.6.8
@angular-devkit/build-angular     0.6.8
@angular-devkit/build-optimizer   0.6.8
@angular-devkit/core              0.6.8
@angular-devkit/schematics        0.6.8
@angular/cdk                      6.2.1
@angular/cli                      6.0.8
@angular/material                 6.2.1
@ngtools/webpack                  6.0.8
@schematics/angular               0.6.8
@schematics/update                0.6.8
rxjs                              6.2.1
typescript                        2.7.2
webpack                           4.8.3

OS: Windows 10 Node Version: v10.4.1

anthonyikeda avatar Jun 16 '18 22:06 anthonyikeda

Hi @anthonyikeda , thank you, for your comprehensive issue reported. I'm sorry for the long delay ... but the answer to your question is likely simple. The dependent 'crypto' library is provided by Node.JS core libs. Currently, there's no support for browser-based applications, which do support this lib, out of the box. Maybe there's a polyfill or siimlar replacement for such.

Currently, I have no spare time available to work on this issue.

nitram509 avatar Jan 07 '21 19:01 nitram509

I fixed this with webpack by using resolve-> alias as described in here https://sanchit3b.medium.com/how-to-polyfill-node-core-modules-in-webpack-5-905c1f5504a0

chris-aeviator avatar Apr 08 '21 21:04 chris-aeviator