Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
TKul6 opened this issue Nov 5, 2017 · 32 comments
Closed

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

TKul6 opened this issue Nov 5, 2017 · 32 comments
Labels
P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful severity3: broken

Comments

@TKul6
Copy link

TKul6 commented Nov 5, 2017

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",

@Scipionh
Copy link

Scipionh commented Nov 6, 2017

Same here

@derekaug
Copy link

derekaug commented Nov 7, 2017

I've spent some time trying to debug this, and no matter what, if I update the @angular/cli package to 1.5.0, this happens to me. I thought maybe it was something in the karma.conf.js and compared my current project's config to a new project's config and it was nearly identical. Even after matching things up as much as possible and disabling some of our plugins this still happens.

@Brocco Brocco added P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful severity3: broken labels Nov 13, 2017
@Scipionh
Copy link

Any news on this issue ?

@lammers
Copy link

lammers commented Nov 27, 2017

I got the same problem with the jsonpath (npm: "jsonpath": "^1.0.0") library.
ng serve and ng build --prod is working. ng test fails.

ERROR in ./node_modules/jsonpath/lib/grammar.js
Module not found: Error: Can't resolve 'fs' in '/home/m500040/gitrepo/lvm-core-components-client-lib/node_modules/jsonpath/lib'
@ ./node_modules/jsonpath/lib/grammar.js 2:9-22
@ ./node_modules/jsonpath/lib/parser.js
@ ./node_modules/jsonpath/lib/index.js
@ ./node_modules/jsonpath/index.js
@ ./src/app/core/services/json-handler/json-handler.service.ts
@ ./src/app/core/services/json-handler/json-handler.service.spec.ts
@ ./src .spec.ts$
@ ./src/test.ts

@adamlubek
Copy link

same problem here

@lammers
Copy link

lammers commented Nov 27, 2017

for my little problem with the jsonpath library a workaround for the issue is using:
import * as jsonPath from 'jsonpath/jsonpath';
instead of
import * as jsonPath from 'jsonpath';
...
jsonPath.query(this._document, path || this.path);

@michelre
Copy link

Same problem, any news?

@Stradivario
Copy link

Hello guys same problem here any news ?

@phamhaibkit
Copy link

same problem,need someone has been resolved

@phong-kite
Copy link

phong-kite commented Dec 6, 2017

I had the same error after running ng test that went away after removing import 'jasmine'; from *.spec.ts files.

If the editor is complaining about missing types for jasmine functions, you can fix that by editing tsconfig.spec.json file:

{
  "compilerOptions": {
    "types": [
      "jasmine",
      ...
    ]
  },
 ...
}

@RadouaneRoufid
Copy link

Same problem here !! Any news ??

@kevinkuszyk
Copy link

This went away for me after updating to angular@5.1.0 & angular-cli@1.6.0 and following these steps:

remove node_modules
remove package-lock.json
npm cache clean -f

(thanks to @istiti for the comment on #7966).

@SearchingSoul
Copy link

thanks @kevinkuszyk, 😢 didn't work for me. Still get multiple "Can't resolve 'fs' in...." with angular-cli@1.6.0.

@RadouaneRoufid
Copy link

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

@derekaug
Copy link

I believe a stray import 'jasmine'; was my issue as well.

@SearchingSoul
Copy link

I have no "import 'jasmine'" in my tests 😒. tsconfig file is like @phong-kite's comment above.

Perhaps the issue is still open & marked as broken/urgent so probably need to wait..? 🤔

@TKul6
Copy link
Author

TKul6 commented Dec 18, 2017

After upgrading to angular 5.0.1 and the cli to 1.6 And removing the import 'jasmine' everything is working fine.

@SearchingSoul
Copy link

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

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

Hope it helps someone.

@phamhaibkit
Copy link

@SearchingSoul ,I would like to sincerely thank you for your help.It's work for me

@Arnaud73
Copy link

Here, with Angular 5.2, Angular CLI 1.6.4, with no reference to import 'jasmine', I had to modify the Karma configuration as described here-before.

Cleaning caches and reinstalling NPM modules did not help.

@xmeng1
Copy link

xmeng1 commented Feb 5, 2018

I think this is the issue of Webpack, see this issue webpack-contrib/css-loader#447 , and @SearchingSoul 's configuration solves it.

@DenysVuika
Copy link

I have suddenly started getting the same issue today after removing lock files, with CLI 1.6.6. The only thing that helped me is the trick with "karma.conf.js" mentioned above:

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

@TKul6
Copy link
Author

TKul6 commented Feb 25, 2018

I had the same error today AGAIN.
The root cause was in the beforeEach() hook when I created the testing module without providing all the necessary mocks.

Now, I get the code shouldn't wok in this scenario, but it would be nice to have more indicative message.

@ravivit9
Copy link

ravivit9 commented Mar 8, 2018

@SearchingSoul the webpack: { node: { fs: 'empty', } } sort of get rid of the fs error but when I run ng test the chrome test window simply not starting.
08 03 2018 11:28:26.966:INFO [launcher]: Launching browser Chrome with unlimited concurrency
08 03 2018 11:28:26.981:INFO [launcher]: Starting browser Chrome 08 03 2018 11:29:26.985:WARN [launcher]: Chrome have not captured in 60000 ms, killing.
08 03 2018 11:29:27.092:INFO [launcher]: Trying to start Chrome again (1/2).
08 03 2018 11:30:27.090:WARN [launcher]: Chrome have not captured in 60000 ms, killing.
08 03 2018 11:30:27.275:INFO [launcher]: Trying to start Chrome again (2/2).
08 03 2018 11:31:27.278:WARN [launcher]: Chrome have not captured in 60000 ms, killing.
08 03 2018 11:31:27.374:ERROR [launcher]: Chrome failed 2 times (timeout). Giving up.

And returns to command prompt.

And the ng test will keep trying to start again and again endlessly. Any thoughts?

BTW, I am not using webpage but angular-cli.

@SearchingSoul
Copy link

@ravivit9 , its only supposed to take care of the 'fs' error. Other errors could be due to other reasons. Yours looks like something to do with your karma 😬.

@havart
Copy link

havart commented Apr 10, 2018

Hi All,
I had the same error.
The error was that I imported the wrong HttpClient (import { HttpClient } from 'selenium-webdriver/http';) module into the component.

@splincode
Copy link

splincode commented Aug 2, 2018

Can't resolve 'child_process' it too have problem

ERROR in ./packages/cli/node_modules/external-editor/main/index.js
Module not found: Error: Can't resolve 'child_process' in '/Users/splincode/Documents/Develop/store/packages/cli/node_modules/external-editor/main'
 @ ./packages/cli/node_modules/external-editor/main/index.js 17:14-38 19:10-34
 @ ./packages/cli/node_modules/inquirer/lib/prompts/editor.js
 @ ./packages/cli/node_modules/inquirer/lib/inquirer.js
 @ ./packages/cli/node_modules/node-plop/lib/node-plop.js
 @ ./packages/cli/node_modules/node-plop/lib/index.js
 @ ./packages/cli/tests/cli.spec.ts
 @ ./packages sync \.spec\.ts$
 @ ./test.ts

I set

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

output

02 08 2018 13:10:38.024:INFO [Chrome 68.0.3440 (Mac OS X 10.13.6)]: Connected on socket vvF5Oc_mUnJw0zmgAAAA with id 94325210
Chrome 68.0.3440 (Mac OS X 10.13.6) ERROR
  {
    "message": "Uncaught Error: process.binding is not supported\nat http://localhost:9876/_karma_webpack_/vendor.js:82248:5\n\nError: process.binding is not supported\n    at Object.push../node_modules/process/browser.js.process.binding (http://localhost:9876/_karma_webpack_/vendor.js:82248:11)\n    at Object.<anonymous> (http://localhost:9876/_karma_webpack_/vendor.js:189191:20)\n    at Object../packages/cli/node_modules/tmp/lib/tmp.js (http://localhost:9876/_karma_webpack_/vendor.js:189788:30)\n    at __webpack_require__ (http://localhost:9876/_karma_webpack_/main.js:77:30)\n    at Object.<anonymous> (http://localhost:9876/_karma_webpack_/vendor.js:134661:10)\n    at Object.<anonymous> (http://localhost:9876/_karma_webpack_/vendor.js:134875:4)\n    at Object../packages/cli/node_modules/external-editor/main/index.js (http://localhost:9876/_karma_webpack_/vendor.js:134877:30)\n    at __webpack_require__ (http://localhost:9876/_karma_webpack_/main.js:77:30)\n    at Object../packages/cli/node_modules/inquirer/lib/prompts/editor.js (http://localhost:9876/_karma_webpack_/vendor.js:149457:22)\n    at __webpack_require__ (http://localhost:9876/_karma_webpack_/main.js:77:30)",
    "str": "Uncaught Error: process.binding is not supported\nat http://localhost:9876/_karma_webpack_/vendor.js:82248:5\n\nError: process.binding is not supported\n    at Object.push../node_modules/process/browser.js.process.binding (http://localhost:9876/_karma_webpack_/vendor.js:82248:11)\n    at Object.<anonymous> (http://localhost:9876/_karma_webpack_/vendor.js:189191:20)\n    at Object../packages/cli/node_modules/tmp/lib/tmp.js (http://localhost:9876/_karma_webpack_/vendor.js:189788:30)\n    at __webpack_require__ (http://localhost:9876/_karma_webpack_/main.js:77:30)\n    at Object.<anonymous> (http://localhost:9876/_karma_webpack_/vendor.js:134661:10)\n    at Object.<anonymous> (http://localhost:9876/_karma_webpack_/vendor.js:134875:4)\n    at Object../packages/cli/node_modules/external-editor/main/index.js (http://localhost:9876/_karma_webpack_/vendor.js:134877:30)\n    at __webpack_require__ (http://localhost:9876/_karma_webpack_/main.js:77:30)\n    at Object../packages/cli/node_modules/inquirer/lib/prompts/editor.js (http://localhost:9876/_karma_webpack_/vendor.js:149457:22)\n    at __webpack_require__ (http://localhost:9876/_karma_webpack_/main.js:77:30)"
  }
Chrome 68.0.3440 (Mac OS X 10.13.6) ERROR
  {
    "message": "Uncaught Error: process.binding is not supported\nat http://localhost:9876/_karma_webpack_/vendor.js:82248:5\n\nError: process.binding is not supported\n    at Object.push../node_modules/process/browser.js.process.binding (http://localhost:9876/_karma_webpack_/vendor.js:82248:11)\n    at Object.<anonymous> (http://localhost:9876/_karma_webpack_/vendor.js:189191:20)\n    at Object../packages/cli/node_modules/tmp/lib/tmp.js (http://localhost:9876/_karma_webpack_/vendor.js:189788:30)\n    at __webpack_require__ (http://localhost:9876/_karma_webpack_/main.js:77:30)\n    at Object.<anonymous> (http://localhost:9876/_karma_webpack_/vendor.js:134661:10)\n    at Object.<anonymous> (http://localhost:9876/_karma_webpack_/vendor.js:134875:4)\n    at Object../packages/cli/node_modules/external-editor/main/index.js (http://localhost:9876/_karma_webpack_/vendor.js:134877:30)\n    at __webpack_require__ (http://localhost:9876/_karma_webpack_/main.js:77:30)\n    at Object../packages/cli/node_modules/inquirer/lib/prompts/editor.js (http://localhost:9876/_karma_webpack_/vendor.js:149457:22)\n    at __webpack_require__ (http://localhost:9876/_karma_webpack_/main.js:77:30)",
    "str": "Uncaught Error: process.binding is not supported\nat http://localhost:9876/_karma_webpack_/vendor.js:82248:5\n\nError: process.binding is not supported\n    at Object.push../node_modules/process/browser.js.process.binding (http://localhost:9876/_karma_webpack_/vendor.js:82248:11)\n    at Object.<anonymous> (http://localhost:9876/_karma_webpack_/vendor.js:189191:20)\n    at Object../packages/cli/node_modules/tmp/lib/tmp.js (http://localhost:9876/_karma_webpack_/vendor.js:189788:30)\n    at __webpack_require__ (http://localhost:9876/_karma_webpack_/main.js:77:30)\n    at Object.<anonymous> (http://localhost:9876/_karma_webpack_/vendor.js:134661:10)\n    at Object.<anonymous> (http://localhost:9876/_karma_webpack_/vendor.js:134875:4)\n    at Object../packages/cli/node_modules/external-editor/main/index.js (http://localhost:9876/_karma_webpack_/vendor.js:134877:30)\n    at __webpack_require__ (http://localhost:9876/_karma_webpack_/main.js:77:30)\n    at Object../packages/cli/node_modules/inquirer/lib/prompts/editor.js (http://localhost:9876/_karma_webpack_/vendor.js:149457:22)\n    at __webpack_require__ (http://localhost:9876/_karma_webpack_/main.js:77:30)"
  }

Chrome 68.0.3440 (Mac OS X 10.13.6) ERROR
  {
    "message": "Uncaught Error: process.binding is not supported\nat http://localhost:9876/_karma_webpack_/vendor.js:82248:5\n\nError: process.binding is not supported\n    at Object.push../node_modules/process/browser.js.process.binding (http://localhost:9876/_karma_webpack_/vendor.js:82248:11)\n    at Object.<anonymous> (http://localhost:9876/_karma_webpack_/vendor.js:189191:20)\n    at Object../packages/cli/node_modules/tmp/lib/tmp.js (http://localhost:9876/_karma_webpack_/vendor.js:189788:30)\n    at __webpack_require__ (http://localhost:9876/_karma_webpack_/main.js:77:30)\n    at Object.<anonymous> (http://localhost:9876/_karma_webpack_/vendor.js:134661:10)\n    at Object.<anonymous> (http://localhost:9876/_karma_webpack_/vendor.js:134875:4)\n    at Object../packages/cli/node_modules/external-editor/main/index.js (http://localhost:9876/_karma_webpack_/vendor.js:134877:30)\n    at __webpack_require__ (http://localhost:9876/_karma_webpack_/main.js:77:30)\n    at Object../packages/cli/node_modules/inquirer/lib/prompts/editor.js (http://localhost:9876/_karma_webpack_/vendor.js:149457:22)\n    at __webpack_require__ (http://localhost:9876/_karma_webpack_/main.js:77:30)",
    "str": "Uncaught Error: process.binding is not supported\nat http://localhost:9876/_karma_webpack_/vendor.js:82248:5\n\nError: process.binding is not supported\n    at Object.push../node_modules/process/browser.js.process.binding (http://localhost:9876/_karma_webpack_/vendor.js:82248:11)\n    at Object.<anonymous> (http://localhost:9876/_karma_webpack_/vendor.js:189191:20)\n    at Object../packages/cli/node_modules/tmp/lib/tmp.js (http://localhost:9876/_karma_webpack_/vendor.js:189788:30)\n    at __webpack_require__ (http://localhost:9876/_karma_webpack_/main.js:77:30)\n    at Object.<anonymous> (http://localhost:9876/_karma_webpack_/vendor.js:134661:10)\n    at Object.<anonymous> (http://localhost:9876/_karma_webpack_/vendor.js:134875:4)\n    at Object../packages/cli/node_modules/external-editor/main/index.js (http://localhost:9876/_karma_webpack_/vendor.js:134877:30)\n    at __webpack_require__ (http://localhost:9876/_karma_webpack_/main.js:77:30)\n    at Object../packages/cli/node_modules/inquirer/lib/prompts/editor.js (http://localhost:9876/_karma_webpack_/vendor.js:149457:22)\n    at __webpack_require__ (http://localhost:9876/_karma_webpack_/main.js:77:30)"
  }

02 08 2018 13:11:04.226:WARN [Chrome 68.0.3440 (Mac OS X 10.13.6)]: Disconnected (1 times)
Chrome 68.0.3440 (Mac OS X 10.13.6) ERROR
  Disconnected
Chrome 68.0.3440 (Mac OS X 10.13.6) ERROR
  Disconnected

Chrome 68.0.3440 (Mac OS X 10.13.6) ERROR
  Disconnected

@kblestarge
Copy link

kblestarge commented Oct 17, 2018

@havart pointed me in the right direction. My errors were caused by importing the wrong EventEmitter in a component:
changed
import { EventEmitter } from 'selenium-webdriver';
to
import { EventEmitter } from '@angular/core';
and the problem is fixed :)

@StanislavChankov
Copy link

@havart pointed me in the right direction. My errors were caused by importing the wrong EventEmitter in a component:
changed
import { EventEmitter } from 'selenium-webdriver';
to
import { EventEmitter } from '@angular/core';
and the problem is fixed :)

This fixes the following errors:
For each node module
ERROR in ./node_modules/...
image

@alan-agius4
Copy link
Collaborator

Thanks for reporting this issue. This issue is now obsolete due to changes in the recent releases. Please update to the most recent Angular CLI version.

If the problem persists after upgrading, please open a new issue, provide a simple repository reproducing the problem, and describe the difference between the expected and current behavior.

@Pradhan10
Copy link

I had the same error after running ng test that went away after removing import 'jasmine'; from *.spec.ts files.

If the editor is complaining about missing types for jasmine functions, you can fix that by editing tsconfig.spec.json file:

{
  "compilerOptions": {
    "types": [
      "jasmine",
      ...
    ]
  },
 ...
}

This worked for me

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful severity3: broken
Projects
None yet
Development

No branches or pull requests