Karma & ionic3: Cannot find module "fs"


#1

Evening! I’ve been trying to get testing working in my ionic3 project. I have been using the example from ionic-unit-testing-example repo, but I can’t seem to get it working. The example repo (https://github.com/driftyco/ionic-unit-testing-example) is running ionic2, but I made a PR for upgrading it to 3.1.1. Got the testing working under this PR: https://github.com/driftyco/ionic-unit-testing-example/pull/31.

However in my real project, with exactly the same dependencies and setup I keep getting cryptic errors which hint that I am using a wrong target for webpack. The error I’m getting is Uncaught Error: Cannot find module "fs", which hints that module “fs” is not accessible by webpack. This would imply target: 'node' rather than the default target: 'web' for webpack config… I’m using exactly the same setup as in the PR shown above, and am stumped after several days of trying to figure it out. Any hints on what else could I try or how to debug would be extremely helpful. Thank you!


#2

There are some problems with Ionic 3 and Unit testing.

But when you try out my branch it should work: https://github.com/driftyco/ionic-unit-testing-example/pull/26


#3

As you can see, no problems

> test-test@0.0.1 test /Users/danielsogl/Documents/Projekte/ionic-unit-testing-example
> karma start ./test-config/karma.conf.js


webpack: Compiled successfully.
webpack: Compiling...
ts-loader: Using typescript@2.2.1 and /Users/danielsogl/Documents/Projekte/ionic-unit-testing-example/tsconfig.json
06 05 2017 21:40:48.790:WARN [karma]: No captured browser, open http://localhost:9876/

WARNING in ./~/@angular/core/@angular/core.es5.js
5870:15-36 Critical dependency: the request of a dependency is an expression

WARNING in ./~/@angular/core/@angular/core.es5.js
5886:15-102 Critical dependency: the request of a dependency is an expression

WARNING in ./~/ionic-angular/util/ng-module-loader.js
54:11-36 Critical dependency: the request of a dependency is an expression

WARNING in ./~/ionic-angular/util/ng-module-loader.js
69:11-36 Critical dependency: the request of a dependency is an expression
webpack: Compiled with warnings.
06 05 2017 21:40:48.809:INFO [karma]: Karma v1.7.0 server started at http://0.0.0.0:9876/
06 05 2017 21:40:48.809:INFO [launcher]: Launching browser Chrome with unlimited concurrency
06 05 2017 21:40:48.914:INFO [launcher]: Starting browser Chrome
06 05 2017 21:40:49.665:INFO [Chrome 58.0.3029 (Mac OS X 10.12.4)]: Connected on socket SF3796WjOX4bw3KMAAAA with id 86607723
....
Chrome 58.0.3029 (Mac OS X 10.12.4): Executed 4 of 4 SUCCESS (1.507 secs / 1.493 secs)

#4

Yup, thanks for the branch and what I have in my app is exactly same as in the unit testing repository. So it should work but doesn’t. I cannot wrap my mind around where to start… :frowning: