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.

Module not found: Error: Can't resolve 'crypto' in 'C:

See original GitHub issue

To get help from the community, check out our Google group.

TensorFlow.js version

@tensorflow/tfjs”: “^0.12.0”,

Browser version

Version 67.0.3396.99 (Official Build) (64-bit)

Describe the problem or feature request

I am using angular 6 with tensorflow.js in the latest versions of tensorflow I get a warning in the console that somme crypto module is not found I have this warning all the time, what should I do/?

Code to reproduce the bug / link to feature request

import * as tf from ‘@tensorflow/tfjs’;

import { Component, OnInit } from '@angular/core';
import * as tf from '@tensorflow/tfjs';



@Component({
  selector: 'app-xor-example',
  templateUrl: './xor-example.component.html',
  styleUrls: ['./xor-example.component.css']
})
export class XorExampleComponent implements OnInit {

  // TRAINING DATA.
  x_train = tf.tensor2d([[0, 0], [0, 1], [1, 0], [1, 1]]);
  y_train = tf.tensor2d([[0], [1], [1], [0]]);

  // Defining a model.
  model: tf.Sequential;

  constructor() { }

  ngOnInit() {

  }

  async initModel() {

    this.model = tf.sequential();
    this.model.add(tf.layers.dense({ units: 8, inputShape: [2], activation: 'tanh' })); // input layer
    this.model.add(tf.layers.dense({ units: 1, activation: 'sigmoid' })); // output layer
    const optimizer = tf.train.sgd(0.01);
    this.model.compile({
      optimizer: optimizer,
      loss: 'binaryCrossentropy',
    });


    // Creating dataset
    const xs = tf.tensor2d([[0, 0], [0, 1], [1, 0], [1, 1]]);
    xs.print();
    const ys = tf.tensor2d([[0], [1], [1], [0]]);
    ys.print();
    // Train the model
    await this.model.fit(xs, ys, {
      batchSize: 1,
      epochs: 1500
    });

    const saveResults = await this.model.save('localstorage://my-model-1');

    const loadedModel = await tf.loadModel('localstorage://my-model-1');
    console.log('Prediction from loaded model:');
    // loadedModel.predict(tf.ones([1, 3])).print();

    this.prediction = this.model.predict(xs);
    console.log(this.prediction);

  }

}

this is from chrome console

Uncaught ReferenceError: global is not defined
    at Object../node_modules/protobufjs/src/util/minimal.js (minimal.js:49)
    at __webpack_require__ (bootstrap:76)
    at Object../node_modules/protobufjs/src/writer.js (writer.js:4)
    at __webpack_require__ (bootstrap:76)
    at Object../node_modules/protobufjs/src/index-minimal.js (index-minimal.js:13)
    at __webpack_require__ (bootstrap:76)
    at Object../node_modules/protobufjs/minimal.js (minimal.js:4)
    at __webpack_require__ (bootstrap:76)
    at Object../node_modules/@tensorflow/tfjs-converter/dist-es6/data/compiled_api.js (compiled_api.js:1)
    at __webpack_require__ (bootstrap:76)

and this is what I see in the console xor test

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:25 (2 by maintainers)

github_iconTop GitHub Comments

110reactions
nkreegercommented, Jul 9, 2018

Hi @George35mk -

I found a couple of cycles to try this out. It looks like this is a problem with the core-parts of the angular webpack bundler. I followed the steps here: https://gist.github.com/niespodd/1fa82da6f8c901d1c33d2fcbb762947d

But instead of using a pre-install, I just hand edited `node_modules/@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs/browser.js’ and changed the lines in that regex:

// old:
node: false,
// new:
node: { crypto: true, stream: true },

I found an issue that you should chime-in on to help fix this down the road: https://github.com/angular/angular-cli/issues/10954

Hope this helps!

31reactions
George35mkcommented, Apr 10, 2019

Because I needed to work with some 3D tensors I installed again the tensorflow.js package in my angular application, and again I get the same error:

Can’t resolve ‘crypto’ in 'C:\Users\user.…

what I found to solve this warnings without modifing any of the angular core files but only your package.json

try this on your package.json

{
  "scripts": { },
  "dependencies": { },
  "devDependencies": { },

  "browser": {
    "crypto": false
  }

}

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' in '/Users/user ...
Stack Overflow for Teams – Start collaborating and sharing organizational knowledge.
Read more >
Can't resolve 'crypto' in node_modules/bson/dist react
I'm using realm-web on my react app to build a simple task reminder app. But, when I start/build the app it is giving...
Read more >
Error: Can't resolve 'crypto' in 'C:\Users\Maduranga\Desktop ...
Module not found : Error: Can't resolve 'crypto' in 'C:\Users\Maduranga\Desktop\laravel\Kithu-Raawa\node_modules\froala-editor\js' BREAKING CHANGE: webpack ...
Read more >
JavaScript : Module not found: Error: Can't resolve 'crypto'
JavaScript : Module not found : Error : Can't resolve ' crypto ' [ Gift : Animated Search Engine : https://bit.ly/AnimSearch ] JavaScript ......
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