Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
338 views
in Technique[技术] by (71.8m points)

javascript - How to replace/supplement a package dependency in npm/angular

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...