Tfjs: Module not found: Error: Can't resolve 'fs'

Created on 22 Feb 2019  路  6Comments  路  Source: tensorflow/tfjs

TensorFlow.js version

@tensorflow/[email protected]

Browser version

Chrome Version 72.0.3626.109 (Official Build) (64-bit)

Describe the problem or feature request

My Angular app was using [email protected]. When I try to upgrade to 0.15.1, I got this error when executing the ng build command. But I am not even using the tfjs-data component.

After I revert tfjs to 0.13.4, my code compiles and the app worked again.

Code to reproduce the bug / link to feature request

All the dependencies in my app.

      "dependencies": {
    "@angular/animations": "^7.2.6",
    "@angular/cdk": "^7.3.3",
    "@angular/common": "^7.2.6",
    "@angular/compiler": "^7.2.6",
    "@angular/core": "^7.2.6",
    "@angular/forms": "^7.2.6",
    "@angular/http": "^7.2.6",
    "@angular/material": "^7.3.3",
    "@angular/platform-browser": "^7.2.6",
    "@angular/platform-browser-dynamic": "^7.2.6",
    "@angular/pwa": "^0.13.3",
    "@angular/router": "^7.2.6",
    "@angular/service-worker": "^7.2.6",
    "@davidshen84/ngx-webcam": "^0.2.2",
    "@tensorflow/tfjs": "^0.15.1",
    "@types/hammerjs": "^2.0.36",
    "angularx-qrcode": "^1.5.3",
    "core-js": "^2.6.5",
    "hammerjs": "^2.0.8",
    "ngx-clipboard": "^11.1.9",
    "ngx-markdown": "^7.1.3",
    "ngx-mathjax": "0.0.4",
    "ngx-store": "^2.1.0",
    "normalize.css": "^8.0.1",
    "prismjs": "^1.15.0",
    "rxjs": "^6.4.0",
    "zone.js": "^0.8.29"
      },
      "devDependencies": {
    "@angular-devkit/build-angular": "^0.13.3",
    "@angular/cli": "^7.3.3",
    "@angular/compiler-cli": "^7.2.6",
    "@angular/language-service": "^7.2.6",
    "@types/del": "^3.0.1",
    "@types/gulp": "^4.0.5",
    "@types/gulp-shell": "0.0.31",
    "@types/jasmine": "^3.3.9",
    "@types/jasminewd2": "^2.0.6",
    "@types/mathjax": "0.0.35",
    "@types/node": "^11.9.4",
    "ajv": "^6.9.1",
    "codelyzer": "~4.5.0",
    "del": "^3.0.0",
    "gulp": "^4.0.0",
    "gulp-shell": "^0.6.5",
    "jasmine-core": "~3.3.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "^4.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "^2.0.5",
    "karma-jasmine": "^2.0.1",
    "karma-jasmine-html-reporter": "^1.4.0",
    "protractor": "^5.4.2",
    "rxjs-spy": "^7.5.0",
    "ts-node": "~8.0.2",
    "tslint": "~5.12.1",
    "typescript": "^3.2.4"
      }
data

Most helpful comment

hi @davidshen84 and @djimoh5

@tensorflow/tfjs-data is part of the @tensorflow/tfjs union package. The error is because of angular-cli does not support modules in node like "fs" and "path". Original issue: https://github.com/angular/angular-cli/issues/10681

I tested locally and the "fs" can be resolve by adding "browser": { "fs": false, "path": false, "os": false} in your package.json (original solution: https://github.com/angular/angular-cli/issues/8272#issuecomment-392777980)

All 6 comments

Experiencing the exact same issue....reverting back to 0.14.1 works for me

hi @davidshen84 and @djimoh5

@tensorflow/tfjs-data is part of the @tensorflow/tfjs union package. The error is because of angular-cli does not support modules in node like "fs" and "path". Original issue: https://github.com/angular/angular-cli/issues/10681

I tested locally and the "fs" can be resolve by adding "browser": { "fs": false, "path": false, "os": false} in your package.json (original solution: https://github.com/angular/angular-cli/issues/8272#issuecomment-392777980)

Instead of asking our users to specify the browser field in their package.json, we should update our tfjs-data/package.json to have 'node-fetch':false, 'string_decoder':false and 'fs':false under package.browser.

I found those 3 packages when I searched for 'require()' usages in tfjs-data repo.

@kangyizhang can you do that? Thanks!

@dsmilkov totally agree with you. Sent PR https://github.com/tensorflow/tfjs-data/pull/147

Why this error happens every time updated version???

@NiNJAD3vel0per are you still seeing this error? Could you make sure you remove node_modules and re-install?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rlexa picture rlexa  路  3Comments

chrisdonahue picture chrisdonahue  路  3Comments

beele picture beele  路  3Comments

lastnod picture lastnod  路  3Comments

kylemcdonald picture kylemcdonald  路  3Comments