angular-cli: Error: Module not found: Error: Can't resolve 'fs'

Bug Report or Feature Request (mark with an x)

- [ x ] bug report -> please search issues before submitting
- [ ] feature request

Versions.

Angular CLI: 1.5.0-rc.6 Node: 6.11.0 OS: darwin x64 Angular: 5.0.0-rc.9 … animations, common, compiler, compiler-cli, core, forms … http, language-service, platform-browser … platform-browser-dynamic, platform-server, router

@angular/cli: 1.5.0-rc.6 @angular-devkit/build-optimizer: 0.0.31 @angular-devkit/core: 0.0.20 @angular-devkit/schematics: 0.0.34 @ngtools/json-schema: 1.1.0 @ngtools/webpack: 1.8.0-rc.6 @schematics/angular: 0.0.49 typescript: 2.6.1 webpack: 3.8.1

Repro steps.

Put some node module inside one file ng test --code-coverage --watch=false

The log given by the failure.

Error: Module not found: Error: Can’t resolve ‘fs’ in ‘/Users/luca/src/app/core/service/config’

Desired functionality.

Prior to update the new version of angular cli and angular 5 the error didn’t happen. When I build or serve, no errors. Fix this functionality before release the final version.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 3
  • Comments: 21 (3 by maintainers)

Most upvoted comments

You can fix it, just add to the “package.json”

"browser": {
    "fs": false,
    "path": false,
    "os": false
  }

Angular apps such as the ones Angular CLI creates are browser apps. fs isn’t available on the browser, it’s only available on node apps.

Even if it worked before this was never a supported feature. I’m sorry but this is working as intended 😕

@filipesilva thanks for the feedback, but Angular applications are supposed to work in a “universal” context, so using different strategy between client and server is reasonable. Also webpack support the ability to override the node modules when the target is the browser. In my opinion this problem is related to the cli because it provide the webpack configuration, but we cannot override it without eject entirely. I ask you to consider to support again this feature.

Closing this issue doesn’t make any sense; why it’s angular “Universal” if it’s suppose to run on browsers only … @filipesilva what’s the point of having isPlatformBrowser() if there is nothing other than browser needs to be supported

Then how are we supposed to use Angular with Electron to make desktop apps if we cannot use node modules like fs, os etc?