isomorphic-git: Error when launching through angular
Hi,
I’m using isomorphic-git in browser through an Angular 7 project. I successfully installed the project with npm install --save isomorphic-git
but when launching my project with ng serve
I encouter the following error :
ERROR in node_modules/isomorphic-git/src/index.d.ts(13,11): error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try `npm i @types/node`.
node_modules/isomorphic-git/src/index.d.ts(115,13): error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try `npm i @types/node`.node_modules/isomorphic-git/src/index.d.ts(561,11): error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try `npm i @types/node`.
@types/node
is already installed and I tried updating it does not solve my problem.
The error is thrown when I import isomorphic-git in my components : import { clone } from 'isomorphic-git'
Is it a known problem and do you know if the library is compatible with angular projects ?
Regards,
Romain.
About this issue
- Original URL
- State: open
- Created 6 years ago
- Comments: 17 (10 by maintainers)
Status update:
We’re much closer to working out-of-the-box with Angular 7! (Edit: the same steps apply for Angular 8.) Which is also means were closer to achieving #698.
I was able to get our demo app running locally with only the following modifications:
package.json
polyfills.ts
tsconfig.json
src/tsconfig.app.json
Only these changes are required with Angular 13:
package.json
polyfills.ts
for angular 8 i had to replace my polyfill.ts with:
(window as any).global.Buffer = (window as any).global.Buffer || require('buffer').Buffer;
instead of this:
tested on Angular 8 by:
in src/assets/somegitfile.js
@wmhilton yes we are doing this for now and it seems to work. Since it’s just the build process that fails, using the library with the pre-built bundle without typings works like a charm !
For the record, if you update
tsconfig.app.json
withtypes: ["node"]
then you do get passed the Buffer error … and if you delete thecorsProxy
argument (because apparently I forgot to add that to the TS definitions for getRemoteInfo)… then you finally get to some meaningful errors:To me this indicates that the library is relying on five node builtins that are normally shimmed by
webpack
: ‘http’, ‘https’, ‘os’, ‘path’, and ‘stream’.The ‘http’ and ‘https’ dependencies will likely go away when I abstract the
httpRemoteHelper
into its own plugin. ‘os’ is being used by ‘globalyzer’… not sure what for, but it might need to be shimmed. ‘path’ is also used by globalyzer but is easy to shim. And ‘stream’… I shouldn’t be relying on stream, I should be usingreadable-stream
like every good node citizen, I’ll have to check what’s up with that.So that’s the plan then. Phase out
simple-get
, replace ‘stream’ with ‘readable-stream’, and probably talk to the author ofglobalyzer
and see if we can make it play ball with Angular 7.