angular / angular-cli

CLI tool for Angular
https://cli.angular.dev
MIT License
26.78k stars 11.98k forks source link

Running `ng test` in windows fails with EMFILE error #977

Closed filipesilva closed 8 years ago

filipesilva commented 8 years ago

Running ng test on Windows, with admin permissions, on a newly generated project fails with a Error: EMFILE: too many open files error.

Running ng serve and ng test --build=false in separate works though.

/cc @wardbell

OS: Windows 10

$ ng --version
angular-cli: 1.0.0-beta.5
node: 5.11.1
os: win32 x64

Reproduction steps:

ng new project
cd project
ng test

Result:

filipe.silva@DESKTOP-7ND6T3R MINGW64 /E/dev/testing/project (master)
$ ng test
Built project successfully. Stored in "dist/".
\ BuildingThe Broccoli Plugin: [BroccoliTypeScriptCompiler] failed with:
Error: EMFILE: too many open files, open 'E:\dev\testing\project\tmp\broccoli_type_script_compiler-input_base_path-sdKfbqXb.tmp\0\src\tsconfig.json'
    at Error (native)
    at Object.fs.openSync (fs.js:584:18)
    at Object.fs.readFileSync (fs.js:431:33)
    at BroccoliTypeScriptCompiler._loadTsConfig (C:\Users\filipe.silva\AppData\Roaming\nvm\v5.11.1\node_modules\angular-cli\lib\broccoli\broccoli-typescript.js:123:34)
    at BroccoliTypeScriptCompiler._createServiceHost (C:\Users\filipe.silva\AppData\Roaming\nvm\v5.11.1\node_modules\angular-cli\lib\broccoli\broccoli-typescript.js:158:25)
    at BroccoliTypeScriptCompiler.build (C:\Users\filipe.silva\AppData\Roaming\nvm\v5.11.1\node_modules\angular-cli\lib\broccoli\broccoli-typescript.js:41:12)
    at C:\Users\filipe.silva\AppData\Roaming\nvm\v5.11.1\node_modules\angular-cli\node_modules\broccoli-caching-writer\index.js:152:21
    at lib$rsvp$$internal$$tryCatch (C:\Users\filipe.silva\AppData\Roaming\nvm\v5.11.1\node_modules\angular-cli\node_modules\rsvp\dist\rsvp.js:1036:16)
    at lib$rsvp$$internal$$invokeCallback (C:\Users\filipe.silva\AppData\Roaming\nvm\v5.11.1\node_modules\angular-cli\node_modules\rsvp\dist\rsvp.js:1048:17)
    at lib$rsvp$$internal$$publish (C:\Users\filipe.silva\AppData\Roaming\nvm\v5.11.1\node_modules\angular-cli\node_modules\rsvp\dist\rsvp.js:1019:11)
    at lib$rsvp$asap$$flush (C:\Users\filipe.silva\AppData\Roaming\nvm\v5.11.1\node_modules\angular-cli\node_modules\rsvp\dist\rsvp.js:1198:9)
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9)

The broccoli plugin was instantiated at:
    at BroccoliTypeScriptCompiler.Plugin (C:\Users\filipe.silva\AppData\Roaming\nvm\v5.11.1\node_modules\angular-cli\node_modules\broccoli-plugin\index.js:10:31)
    at BroccoliTypeScriptCompiler.CachingWriter [as constructor] (C:\Users\filipe.silva\AppData\Roaming\nvm\v5.11.1\node_modules\angular-cli\node_modules\broccoli-caching-writer\index.js:21:10)
    at BroccoliTypeScriptCompiler (C:\Users\filipe.silva\AppData\Roaming\nvm\v5.11.1\node_modules\angular-cli\lib\broccoli\broccoli-typescript.js:26:49)
    at Angular2App._getTsTree (C:\Users\filipe.silva\AppData\Roaming\nvm\v5.11.1\node_modules\angular-cli\lib\broccoli\angular2-app.js:321:18)
    at Angular2App._buildTree (C:\Users\filipe.silva\AppData\Roaming\nvm\v5.11.1\node_modules\angular-cli\lib\broccoli\angular2-app.js:116:23)
    at new Angular2App (C:\Users\filipe.silva\AppData\Roaming\nvm\v5.11.1\node_modules\angular-cli\lib\broccoli\angular2-app.js:53:23)
    at module.exports (E:\dev\testing\project\angular-cli-build.js:6:10)
    at Class.module.exports.Task.extend.setupBroccoliBuilder (C:\Users\filipe.silva\AppData\Roaming\nvm\v5.11.1\node_modules\angular-cli\node_modules\angular-cli\lib\models\builder.js:55:19)
    at Class.module.exports.Task.extend.init (C:\Users\filipe.silva\AppData\Roaming\nvm\v5.11.1\node_modules\angular-cli\node_modules\angular-cli\lib\models\builder.js:89:10)
    at new Class (C:\Users\filipe.silva\AppData\Roaming\nvm\v5.11.1\node_modules\angular-cli\node_modules\core-object\core-object.js:18:12)
    at Class.module.exports.Task.extend.run (C:\Users\filipe.silva\AppData\Roaming\nvm\v5.11.1\node_modules\angular-cli\node_modules\angular-cli\lib\tasks\build-watch.js:17:16)
    at C:\Users\filipe.silva\AppData\Roaming\nvm\v5.11.1\node_modules\angular-cli\addon\ng2\commands\test.js:69:46
    at lib$rsvp$$internal$$tryCatch (C:\Users\filipe.silva\AppData\Roaming\nvm\v5.11.1\node_modules\angular-cli\node_modules\rsvp\dist\rsvp.js:1036:16)
    at lib$rsvp$$internal$$invokeCallback (C:\Users\filipe.silva\AppData\Roaming\nvm\v5.11.1\node_modules\angular-cli\node_modules\rsvp\dist\rsvp.js:1048:17)
    at lib$rsvp$$internal$$publish (C:\Users\filipe.silva\AppData\Roaming\nvm\v5.11.1\node_modules\angular-cli\node_modules\rsvp\dist\rsvp.js:1019:11)
    at lib$rsvp$asap$$flush (C:\Users\filipe.silva\AppData\Roaming\nvm\v5.11.1\node_modules\angular-cli\node_modules\rsvp\dist\rsvp.js:1198:9)

The Broccoli Plugin: [BroccoliTypeScriptCompiler] failed with:
Error: EMFILE: too many open files, open 'E:\dev\testing\project\tmp\broccoli_type_script_compiler-input_base_path-sdKfbqXb.tmp\0\src\tsconfig.json'
    at Error (native)
    at Object.fs.openSync (fs.js:584:18)
    at Object.fs.readFileSync (fs.js:431:33)
    at BroccoliTypeScriptCompiler._loadTsConfig (C:\Users\filipe.silva\AppData\Roaming\nvm\v5.11.1\node_modules\angular-cli\lib\broccoli\broccoli-typescript.js:123:34)
    at BroccoliTypeScriptCompiler._createServiceHost (C:\Users\filipe.silva\AppData\Roaming\nvm\v5.11.1\node_modules\angular-cli\lib\broccoli\broccoli-typescript.js:158:25)
    at BroccoliTypeScriptCompiler.build (C:\Users\filipe.silva\AppData\Roaming\nvm\v5.11.1\node_modules\angular-cli\lib\broccoli\broccoli-typescript.js:41:12)
    at C:\Users\filipe.silva\AppData\Roaming\nvm\v5.11.1\node_modules\angular-cli\node_modules\broccoli-caching-writer\index.js:152:21
    at lib$rsvp$$internal$$tryCatch (C:\Users\filipe.silva\AppData\Roaming\nvm\v5.11.1\node_modules\angular-cli\node_modules\rsvp\dist\rsvp.js:1036:16)
    at lib$rsvp$$internal$$invokeCallback (C:\Users\filipe.silva\AppData\Roaming\nvm\v5.11.1\node_modules\angular-cli\node_modules\rsvp\dist\rsvp.js:1048:17)
    at lib$rsvp$$internal$$publish (C:\Users\filipe.silva\AppData\Roaming\nvm\v5.11.1\node_modules\angular-cli\node_modules\rsvp\dist\rsvp.js:1019:11)
    at lib$rsvp$asap$$flush (C:\Users\filipe.silva\AppData\Roaming\nvm\v5.11.1\node_modules\angular-cli\node_modules\rsvp\dist\rsvp.js:1198:9)
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9)

The broccoli plugin was instantiated at:
    at BroccoliTypeScriptCompiler.Plugin (C:\Users\filipe.silva\AppData\Roaming\nvm\v5.11.1\node_modules\angular-cli\node_modules\broccoli-plugin\index.js:10:31)
    at BroccoliTypeScriptCompiler.CachingWriter [as constructor] (C:\Users\filipe.silva\AppData\Roaming\nvm\v5.11.1\node_modules\angular-cli\node_modules\broccoli-caching-writer\index.js:21:10)
    at BroccoliTypeScriptCompiler (C:\Users\filipe.silva\AppData\Roaming\nvm\v5.11.1\node_modules\angular-cli\lib\broccoli\broccoli-typescript.js:26:49)
    at Angular2App._getTsTree (C:\Users\filipe.silva\AppData\Roaming\nvm\v5.11.1\node_modules\angular-cli\lib\broccoli\angular2-app.js:321:18)
    at Angular2App._buildTree (C:\Users\filipe.silva\AppData\Roaming\nvm\v5.11.1\node_modules\angular-cli\lib\broccoli\angular2-app.js:116:23)
    at new Angular2App (C:\Users\filipe.silva\AppData\Roaming\nvm\v5.11.1\node_modules\angular-cli\lib\broccoli\angular2-app.js:53:23)
    at module.exports (E:\dev\testing\project\angular-cli-build.js:6:10)
    at Class.module.exports.Task.extend.setupBroccoliBuilder (C:\Users\filipe.silva\AppData\Roaming\nvm\v5.11.1\node_modules\angular-cli\node_modules\angular-cli\lib\models\builder.js:55:19)
    at Class.module.exports.Task.extend.init (C:\Users\filipe.silva\AppData\Roaming\nvm\v5.11.1\node_modules\angular-cli\node_modules\angular-cli\lib\models\builder.js:89:10)
    at new Class (C:\Users\filipe.silva\AppData\Roaming\nvm\v5.11.1\node_modules\angular-cli\node_modules\core-object\core-object.js:18:12)
    at Class.module.exports.Task.extend.run (C:\Users\filipe.silva\AppData\Roaming\nvm\v5.11.1\node_modules\angular-cli\node_modules\angular-cli\lib\tasks\build-watch.js:17:16)
    at C:\Users\filipe.silva\AppData\Roaming\nvm\v5.11.1\node_modules\angular-cli\addon\ng2\commands\test.js:69:46
    at lib$rsvp$$internal$$tryCatch (C:\Users\filipe.silva\AppData\Roaming\nvm\v5.11.1\node_modules\angular-cli\node_modules\rsvp\dist\rsvp.js:1036:16)
    at lib$rsvp$$internal$$invokeCallback (C:\Users\filipe.silva\AppData\Roaming\nvm\v5.11.1\node_modules\angular-cli\node_modules\rsvp\dist\rsvp.js:1048:17)
    at lib$rsvp$$internal$$publish (C:\Users\filipe.silva\AppData\Roaming\nvm\v5.11.1\node_modules\angular-cli\node_modules\rsvp\dist\rsvp.js:1019:11)
    at lib$rsvp$asap$$flush (C:\Users\filipe.silva\AppData\Roaming\nvm\v5.11.1\node_modules\angular-cli\node_modules\rsvp\dist\rsvp.js:1198:9)
Foxandxss commented 8 years ago

Yup, same error as Ward's.

My question is: If ng serve builds the project succesfully, why ng test doesn't? Are they building in a different way?

filipesilva commented 8 years ago

They might, yes. Investigating.

filipesilva commented 8 years ago

Possibly related: https://github.com/angular/angular/issues/4525

filipesilva commented 8 years ago

The explanation for why ng test fails but serving and testing works seems to be that individual processes have a file descriptor limit (see http://stackoverflow.com/questions/31932729/open-too-many-files-emfile-error-in-windows-7). Thus running in separate doubles the file limit.

filipesilva commented 8 years ago

Further investigation shows that the problem occurs because of karma serving the files in dist/vendor/.

Effectively, the process is watching those files files twice - once for rebuilding them and once for testing them.

I don't have a solution for this at the moment.

JohannesHoppe commented 8 years ago

FYI, I changed my "test" npm-script to: ng build && ng test --build=false

That's a good workaround until this is fixed.

filipesilva commented 8 years ago

@JohannesHoppe your solution is better than the one I put up in https://github.com/angular/angular-cli/pull/991/files. Would you be interested in making a PR replacing my warning?

JohannesHoppe commented 8 years ago

Sure, I'll do that. :smile:

Blasz commented 8 years ago

I think it should be ng build && ng test --build=false --watch=false. There isn't much point keeping the tester in watch mode if the sources don't rebuild.

I still think separate ng serve + ng test processes are good for running tests in watch mode whereas the npm script change is better for running it once.

francisoud commented 8 years ago

@JohannesHoppe your workaround works but only when running >npm run test Do you know how to achieve the same when running ? >ng test

@filipesilva I tried to dig into angular-cli code but didn't found where it was specified :(

FYI

>ng --version
angular-cli: 1.0.0-beta.8
node: 6.2.1
os: win32 x64
filipesilva commented 8 years ago

Issue made obsolete by #1455.

comfroels commented 8 years ago

YES!!! Webpack awesome thanks! Just ran into this this morning

willi84 commented 8 years ago

I also have this issue and on Win10 and using ng test --watch=false as a workaround

Marianogboo commented 7 years ago

please guys, i am trying to run an ng test and i am getting the following error Missing 'angularCli.config' entry in Karma config Error: Missing 'angularCli.config' entry in Karma config

at init (C:\Users\Chisom\Documents\GitHub\OryxMCIv2\src\OryxMCI_web\node_modules\angular-cli\plugins\karma.js:9:11)
at Array.invoke (C:\Users\Chisom\Documents\GitHub\OryxMCIv2\src\OryxMCI_web\node_modules\di\lib\injector.js:75:15)
at Injector.get (C:\Users\Chisom\Documents\GitHub\OryxMCIv2\src\OryxMCI_web\node_modules\di\lib\injector.js:48:43)
at C:\Users\Chisom\Documents\GitHub\OryxMCIv2\src\OryxMCI_web\node_modules\karma\lib\server.js:138:20
at Array.forEach (native)
at Server._start (C:\Users\Chisom\Documents\GitHub\OryxMCIv2\src\OryxMCI_web\node_modules\karma\lib\server.js:137:21)
at Injector.invoke (C:\Users\Chisom\Documents\GitHub\OryxMCIv2\src\OryxMCI_web\node_modules\di\lib\injector.js:75:15)
at Server.start (C:\Users\Chisom\Documents\GitHub\OryxMCIv2\src\OryxMCI_web\node_modules\karma\lib\server.js:102:18)
at C:\Users\Chisom\Documents\GitHub\OryxMCIv2\src\OryxMCI_web\node_modules\angular-cli\tasks\test.js:30:25
at Class.run (C:\Users\Chisom\Documents\GitHub\OryxMCIv2\src\OryxMCI_web\node_modules\angular-cli\tasks\test.js:15:16)
at Class.run (C:\Users\Chisom\Documents\GitHub\OryxMCIv2\src\OryxMCI_web\node_modules\angular-cli\commands\test.js:29:25)
at Class.<anonymous> (C:\Users\Chisom\Documents\GitHub\OryxMCIv2\src\OryxMCI_web\node_modules\angular-cli\angular-cli\lib\models\command.js:152:17)
at process._tickCallback (internal/process/next_tick.js:103:7)

here is my karma.config module.exports = function (config) { config.set({ basePath: '', frameworks: ['jasmine', 'angular-cli'], plugins: [ require('karma-jasmine'), require('karma-chrome-launcher'), require('karma-remap-istanbul'), require('angular-cli/plugins/karma') ], files: [ { pattern: './src/test.ts', watched: false } ], preprocessors: { './src/test.ts': ['angular-cli'] }, remapIstanbulReporter: { reports: { html: 'coverage', lcovonly: './coverage/coverage.lcov' } }, angularCliConfig: './angular-cli.json', angularCli: { config: './angular-cli.json', environment: 'dev' }, reporters: ['progress', 'karma-remap-istanbul'], port: 9876, colors: true, logLevel: config.LOG_INFO, autoWatch: true, browsers: ['Chrome'], singleRun: false }); };

please any work-around, i am desperate here.

angular-automatic-lock-bot[bot] commented 5 years ago

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.