I have an angular application and have to use an npm package @inrupt/solid-client-authn-browser
.
This package has a dependency for jwa
, crypto
, stream
and buffer
packages, all of which are originally created for node.js (server-side), not made to run in browser.
The creators suggest polyfilling these for the browser alternatives (https://github.com/inrupt/solid-client-js/issues/608), which they do using webpack.
I found that the buffer
can be fixed by adding this to polyfills.ts
(window as any).global = window;
global.Buffer = global.Buffer || require('buffer').Buffer;
But what I haven't figured out is how to fix the jwa's package dependency on crypto.
In the package (node_modules)/jwa/index.js, there is
var crypto = require('crypto');
and this fails on angular build (standard ng build
):
Error: ./node_modules/jwa/index.js
Module not found: Error: Can't resolve 'crypto' in 'C:devWindowssrck diplomceinbox
ode_modulesjwa'
There is the crypto-browserify
package. All I need is a way to tell npm to use crypto-browserify
instead of crypto
.
Is there a way to do this (to keep builds, I don't want to directly edit the generated files in node_modules)?
my versions: Angular CLI: 11.0.7, Angular: 11.0.9
question from:
https://stackoverflow.com/questions/65927427/how-to-replace-supplement-a-package-dependency-in-npm-angular 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…