Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Can't resolve 'crypto' #93

Closed
yunwwang opened this issue Mar 15, 2019 · 9 comments
Closed

Error: Can't resolve 'crypto' #93

yunwwang opened this issue Mar 15, 2019 · 9 comments

Comments

@yunwwang
Copy link

Expected Behavior

Angular 6 app launches without error

Actual Behavior

Angular 6 app launches with "Can't resolve 'crypto'" error

Steps to Reproduce the Problem

  1. Create an angular 6 app

  2. install fhir-kit-client using npm

  3. import fhir-kit-client to component

  4. add code to noOnInit()
    `
    public ngOnInit(): void {
    const Client = require('fhir-kit-client');
    const iss = this._route.snapshot.queryParams['iss'];

    const fhirClient = new Client({baseUrl: iss});
    ...
    }
    `

  5. start the app using "ng serve"

Specifications

  • Version:
  • Platform:
  • Subsystem:
@bkaney
Copy link
Member

bkaney commented Mar 16, 2019

@froid1911
Copy link

you are closing #93 because of dupe of #92
and you are closing #92 because of dupe of #93

@bkaney
Copy link
Member

bkaney commented Mar 26, 2019

Hi @froid1911#93 (this one) is currently open? Not sure what you mean by your comment...

In all likelihood we will include instructions on how to adjust the webpack configuration for Angular 6 per the links above. What are your thoughts?

@froid1911
Copy link

opsi, thought it got closed. sry for that :-) ........

@yunwwang
Copy link
Author

Worked whole afternoon trying to get angular 6 project working. Tried using @angular-builders/custom-webpack. Now ng build works but ng serve still not working. If anyone have a successful angular 6 project using this client js, please let me know.

@bkaney
Copy link
Member

bkaney commented Apr 19, 2019

I looked at this a bit today. To make requests work on the server for node apps, we use request, (which depends on the crypto library, not avail in the browser). For the browser, we use request-promise-native. However, request-promise-native has a peer dependency of request. Angular doesn't like this even though the polyfill never actually loads the one requiring crypto.

@foxtree
Copy link
Contributor

foxtree commented Apr 26, 2019

but ng serve still not working.

@yunwwang

I tried following the guide, here, and it seems to work with Angular-7:
https://codeburst.io/customizing-angular-cli-6-build-an-alternative-to-ng-eject-a48304cd3b21
(^This guide mentions Angular-6 -- if for any reason this does not work with 6, try upgrading to Angular 7?)

  • You would have to npm i -D (or, yarn add -D) @angular-builders/dev-server

  • The following changes to angular.json seemed to enable ng serve to work with fhir-kit-client:

image

@yunwwang
Copy link
Author

yunwwang commented May 3, 2019

@foxtree Do you mind to create a sample codes for Anguar 6/7? That would be really helpful.

@bkaney
Copy link
Member

bkaney commented Jul 31, 2019

This should be resolved in 1.4.0 now. Also check out the examples here: https://github.com/Vermonster/fhir-kit-client-examples

@bkaney bkaney closed this as completed Jul 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants