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.

ng test fails Module not found: Error: Can't resolve 'fs'

See original GitHub issue

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 Node: 9.0.0 OS: win32 x64 Angular: 5.0.0 … animations, common, compiler, compiler-cli, core, forms … http, language-service, platform-browser … platform-browser-dynamic, router

@angular/cli: 1.5.0 @angular-devkit/build-optimizer: 0.0.32 @angular-devkit/core: 0.0.20 @angular-devkit/schematics: 0.0.35 @ngtools/json-schema: 1.1.0 @ngtools/webpack: 1.8.0 @schematics/angular: 0.1.0 typescript: 2.4.2 webpack: 3.8.1

Repro steps.

ng test

Omits the following error:

ERROR in ./node_modules/fs.realpath/index.js Module not found: Error: Can’t resolve ‘fs’ in XXXX\node_modules\fs.realpath’ @ ./node_modules/fs.realpath/index.js 8:9-22 @ ./node_modules/jasmine/node_modules/glob/sync.js @ ./node_modules/jasmine/node_modules/glob/glob.js @ ./node_modules/jasmine/lib/jasmine.js @ ./src/client/app/account/login/login.component.spec.ts @ ./src/client .spec.ts$ @ ./src/client/test.ts

ERROR in ./node_modules/fs.realpath/old.js Module not found: Error: Can’t resolve ‘fs’ in ‘XXXX\node_modules\fs.realpath’ @ ./node_modules/fs.realpath/old.js 24:9-22 @ ./node_modules/fs.realpath/index.js @ ./node_modules/jasmine/node_modules/glob/sync.js @ ./node_modules/jasmine/node_modules/glob/glob.js @ ./node_modules/jasmine/lib/jasmine.js @ ./src/client/app/account/login/login.component.spec.ts @ ./src/client .spec.ts$ @ ./src/client/test.ts

ERROR in ./node_modules/jasmine/node_modules/glob/sync.js Module not found: Error: Can’t resolve ‘fs’ in ‘XXXX\node_modules\jasmine\node_modules\glob’ @ ./node_modules/jasmine/node_modules/glob/sync.js 4:9-22 @ ./node_modules/jasmine/node_modules/glob/glob.js @ ./node_modules/jasmine/lib/jasmine.js @ ./src/client/app/account/login/login.component.spec.ts @ ./src/client .spec.ts$ @ ./src/client/test.ts

ERROR in ./node_modules/jasmine/node_modules/glob/glob.js Module not found: Error: Can’t resolve ‘fs’ inXXXX\node_modules\jasmine\node_modules\glob’ @ ./node_modules/jasmine/node_modules/glob/glob.js 43:9-22 @ ./node_modules/jasmine/lib/jasmine.js @ ./src/client/app/account/login/login.component.spec.ts @ ./src/client .spec.ts$ @ ./src/client/test.ts

ERROR in ./node_modules/jasmine/node_modules/jasmine-core/lib/jasmine-core.js Module not found: Error: Can’t resolve ‘fs’ in ‘XXXX\node_modules\jasmine\node_modules\jasmine-core\lib’ @ ./node_modules/jasmine/node_modules/jasmine-core/lib/jasmine-core.js 5:9-22 @ ./node_modules/jasmine/lib/jasmine.js @ ./src/client/app/account/login/login.component.spec.ts @ ./src/client .spec.ts$ @ ./src/client/test.ts

Desired functionality.

Run the tests

Mention any other details that might be useful.

It happened when I upgraded from cli 1.47 to 1.5.0.

Jasmine packages: “jasmine”: “^2.8.0”, “jasmine-core”: “~2.5.2”, “jasmine-spec-reporter”: “~3.2.0”

Karma packages:

“karma”: “~1.5.0”, “karma-chrome-launcher”: “~2.0.0”, “karma-cli”: “~1.0.1”, “karma-coverage-istanbul-reporter”: “^1.0.0”, “karma-jasmine”: “~1.1.0”, “karma-jasmine-html-reporter”: “^0.2.2”, “karma-junit-reporter”: “^1.2.0”, “karma-mocha”: “^1.3.0”, “karma-phantomjs-launcher”: “^1.0.4”,

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:41
  • Comments:32

github_iconTop GitHub Comments

54reactions
SearchingSoulcommented, Dec 20, 2017

What worked for me is adding the following to karma.conf.js

webpack: { node: { fs: 'empty', } }

Hope it helps someone.

18reactions
RadouaneRoufidcommented, Dec 13, 2017

I had a "import 'jasmine'" in one of my tests. Removing it solved the problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Module not found: Error: Can't resolve 'fs' in - Stack Overflow
I found a possible solution, that you have to put some configuration in one of the node_modules. But I think that is not...
Read more >
Angular 12 - Fixing Module not found: Error: Can't resolve 'fs'
The above is how I fixed mine. The idea is, for whatever “cannot import module” whatever error that shows, it's possible the package...
Read more >
module not found: error: can't resolve 'fs' angular - You.com
The error is because angular-CLI does not support modules in Nodejs like "fs" and "path". Add the following to the root of the...
Read more >
Angular CLI: "Module not found: Error: Can't resolve..."
The problem. After upgrading one of my Angular applications, from version 5 to version 6, I tried to build it (using ng build...
Read more >
cannot find module [Node npm Error Solved] - freeCodeCamp
When you get the “cannot find module” error, or “module not found”, it means you've not installed the package you're trying to use....
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