question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: Can't resolve 'crypto'

See original GitHub issue

I’m using @angular version 6.0.0-rc.5

and I cannot compile this code

import { Injectable } from '@angular/core';
import * as web3 from 'web3';

@Injectable()
export class Web3Provider {

  constructor(){
    console.log(web3) 
  }

}

I got this error

ERROR in ../node_modules/eth-lib/lib/bytes.js
Module not found: Error: Can't resolve 'crypto' in '*/node_modules/eth-lib/lib'
ERROR in ../node_modules/web3-eth-accounts/node_modules/eth-lib/lib/bytes.js
Module not found: Error: Can't resolve 'crypto' in '*/node_modules/web3-eth-accounts/node_modules/eth-lib/lib'

With Angular version 5 everything works fine.

My package json is

  "dependencies": {
    "@angular/animations": "^6.0.0-rc.5",
    "@angular/cdk": "^6.0.0-rc.5",
    "@angular/common": "^6.0.0-rc.5",
    "@angular/compiler": "^6.0.0-rc.5",
    "@angular/core": "^6.0.0-rc.5",
    "@angular/forms": "^6.0.0-rc.5",
    "@angular/http": "^6.0.0-rc.5",
    "@angular/material": "^6.0.0-rc.5",
    "@angular/platform-browser": "^6.0.0-rc.5",
    "@angular/platform-browser-dynamic": "^6.0.0-rc.5",
    "@angular/platform-server": "^6.0.0-rc.5",
    "@angular/router": "^6.0.0-rc.5",
    "@angular/service-worker": "^6.0.0-rc.5",
    "@nguniversal/express-engine": "^5.0.0",
    "@nguniversal/module-map-ngfactory-loader": "^5.0.0",
    "compression": "^1.7.2",
    "core-js": "^2.5.5",
    "ethereumjs-tx": "^1.3.4",
    "material-design-icons": "^3.0.1",
    "rxjs": "6.0.0-rc.0",
    "spdy": "^3.4.7",
    "tinymce": "^4.7.10",
    "ts-loader": "^4.2.0",
    "web-animations-js": "^2.3.1",
    "web3": "^1.0.0-beta.34",
    "webpack": "^4.5.0",
    "webpack-cli": "^2.0.14",
    "zone.js": "^0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.5.0",
    "@angular/cli": "^6.0.0-rc.4",
    "@angular/compiler-cli": "^6.0.0-rc.5",
    "@angular/language-service": "^6.0.0-rc.5",
    "@types/node": "^9.6.4",
    "express": "^4.16.3",
    "node-sass": "^4.8.3",
    "reflect-metadata": "^0.1.12",
    "typescript": "~2.7.2"
  }

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:11
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

12reactions
isaackwancommented, May 5, 2018

I actually have the same the same problem. The issue here is that from Angular 6 on, apparently the node module polyfills from webpack are not bundled.

This is not a problem previously, because (1) they are bundled, except the crypto module and (2) even if they were not, we can edit the webpack config file by ejecting.

Currently eject is no longer possible:

The 'eject' command has been temporarily disabled, as it is not yet compatible with the new
angular.json format. The new configuration format provides further flexibility to modify the
configuration of your workspace without ejecting. Ejection will be re-enabled in a future
release of the CLI.

Will post more updates/create new issue as I gather more information. Thanks.

– Update – Great, the file’s location has changed before Angular CLI v6

Before: https://github.com/angular/angular-cli/blob/v1.7.4/packages/%40angular/cli/models/webpack-configs/browser.ts#L111

    node: {
      fs: 'empty',
      global: true,
      crypto: 'empty',
      tls: 'empty',
      net: 'empty',
      process: true,
      module: false,
      clearImmediate: false,
      setImmediate: false
    }

After: https://github.com/angular/devkit/blob/v6.0.0/packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/browser.ts#L128

node: false,
6reactions
splincodecommented, Apr 17, 2018

And here is the angular? This is a problem with another package Either make a repository on the github with an error

Read more comments on GitHub >

github_iconTop Results From Across the Web

Module not found: Error: Can't resolve 'crypto' - Stack Overflow
I ran into a similar issue lately while trying to use another library (tiff.js) in a small project I was experimenting with.
Read more >
Module not found: Error: Can't resolve 'crypto' [Solved]
The error "Module not found: Error: Can't resolve 'crypto'" occurs because there has been a breaking change in Webpack version 5. To solve...
Read more >
Can't resolve 'crypto' in node_modules/bson/dist react
The app is running fine but I'm having a problem when I deploy the app to Netlify. I have to configure the deploy...
Read more >
Module not found: Error: Can't resolve 'crypto' #318 - GitHub
I have use CRA (create-react-app). react-scripts Version 5.0.0 Error Message: WARNING in ./node_modules/froala-editor/js/plugins.pkgd.min.js ...
Read more >
Module not found: Error: Can't resolve 'crypto' in '/Users/user ...
1 Answer 1 · Thank i recompiled with the some corrections i saw on the forum but i got the following error. –...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found