{"action":"created","issue":{"url":"https://api.github.com/repos/webpack/karma-webpack/issues/154","repository_url":"https://api.github.com/repos/webpack/karma-webpack","labels_url":"https://api.github.com/repos/webpack/karma-webpack/issues/154/labels{/name}","comments_url":"https://api.github.com/repos/webpack/karma-webpack/issues/154/comments","events_url":"https://api.github.com/repos/webpack/karma-webpack/issues/154/events","html_url":"https://github.com/webpack/karma-webpack/issues/154","id":168305796,"number":154,"title":"possible timing problem: Error: no such file or directory","user":{"login":"madebits","id":9382824,"avatar_url":"https://avatars.githubusercontent.com/u/9382824?v=3","gravatar_id":"","url":"https://api.github.com/users/madebits","html_url":"https://github.com/madebits","followers_url":"https://api.github.com/users/madebits/followers","following_url":"https://api.github.com/users/madebits/following{/other_user}","gists_url":"https://api.github.com/users/madebits/gists{/gist_id}","starred_url":"https://api.github.com/users/madebits/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/madebits/subscriptions","organizations_url":"https://api.github.com/users/madebits/orgs","repos_url":"https://api.github.com/users/madebits/repos","events_url":"https://api.github.com/users/madebits/events{/privacy}","received_events_url":"https://api.github.com/users/madebits/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/webpack/karma-webpack/labels/needs%20investigation","name":"needs investigation","color":"cc317c"},{"url":"https://api.github.com/repos/webpack/karma-webpack/labels/question","name":"question","color":"0052cc"}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":8,"created_at":"2016-07-29T11:31:56Z","updated_at":"2016-10-17T22:48:12Z","closed_at":"2016-10-03T16:48:51Z","body":"I get an error up and now in the build server, which I do not have locally:\r\n\r\n```\r\n...\r\nwebpack: bundle is now VALID.\r\nwebpack: bundle is now INVALID.\r\n{ [Error: no such file or directory]\r\n   code: 'ENOENT',\r\n   errno: 34,\r\n   message: 'no such file or directory',\r\n   path: '/_karma_webpack_/test.js' }\r\n Error: no such file or directory\r\n     at MemoryFileSystem.readFileSync (C:\\PATH\\node_modules\\memory-fs\\lib\\MemoryFileSystem.js:114:10)\r\n     at MemoryFileSystem.readFile (C:\\PATH\\node_modules\\memory-fs\\lib\\MemoryFileSystem.js:297:21)\r\n     at doRead (C:\\PATH\\node_modules\\karma-webpack\\index.js:156:26)\r\n     at Plugin.readFile (C:\\PATH\\node_modules\\karma-webpack\\index.js:160:3)\r\n     at C:\\PATH\\node_modules\\karma-webpack\\index.js:176:17\r\n     at nextPreprocessor (C:\\PATH\\node_modules\\karma\\lib\\preprocessor.js:35:26)\r\n     at C:\\PATH\\node_modules\\karma\\lib\\preprocessor.js:114:9\r\n     at module.exports (C:\\PATH\\node_modules\\isbinaryfile\\index.js:28:12)\r\n     at C:\\PATH\\node_modules\\karma\\lib\\preprocessor.js:79:7\r\n     at C:\\PATH\\node_modules\\graceful-fs\\graceful-fs.js:78:16\r\n     at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:404:3)\r\n```\r\n\r\n`test.js` file is there in disk, and inside `test.js` I use use `require.context` to load all `spec.ts` files in a folder.\r\n\r\nAs this error only happens sometimes in my build server and often a restart of build with same code state works, I suspect this can be some timing issue.\r\n\r\nI looked at the failing code in `karma-webpack\\index.js` inside `function createPreprocesor ...`. There if the file is not found the webpack bundle is invalidated:\r\n\r\n```\r\nif (webpackPlugin.addFile(file.path)) {\r\n\t\t\t// recompile as we have an asset that we have not seen before\r\n\t\t\twebpackPlugin.middleware.invalidate();\r\n\t\t}\r\n```\r\n\r\nAfter that the code there immediately tries to read the file:\r\n\r\n```\r\n// read blocks until bundle is done\r\nwebpackPlugin.readFile ...\r\n```\r\n\r\nGiven that my file `test.js` uses `require.context` it may take some time for it to available in the memory file system used by the webpack middleware.\r\n\r\nI am not sure, but I have the feeling changing the readFile code line to run within `waitUntilValid` would fix the error I face:\r\n\r\n```\r\n...\r\nwebpackPlugin.middleware.waitUntilValid(function(){\r\n\t\t\t// read blocks until bundle is done\r\n\t\t\twebpackPlugin.readFile(path.relative(basePath, file.path), function(err, content) {\r\n\t\t\t\tif (err) {\r\n\t\t\t\t\tthrow err;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tdone(err, content && content.toString());\r\n\t\t\t});\r\n\t\t});\r\n```\r\n\r\nI tested this and it has no side effects that I can see in my case, but I do not know the webpack plugins so good to be sure this can really fix it. Can someone with more knowledge confirm whether my suspicion and fix are correct?\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/webpack/karma-webpack/issues/comments/254357155","html_url":"https://github.com/webpack/karma-webpack/issues/154#issuecomment-254357155","issue_url":"https://api.github.com/repos/webpack/karma-webpack/issues/154","id":254357155,"user":{"login":"jrgleason","id":1319151,"avatar_url":"https://avatars.githubusercontent.com/u/1319151?v=3","gravatar_id":"","url":"https://api.github.com/users/jrgleason","html_url":"https://github.com/jrgleason","followers_url":"https://api.github.com/users/jrgleason/followers","following_url":"https://api.github.com/users/jrgleason/following{/other_user}","gists_url":"https://api.github.com/users/jrgleason/gists{/gist_id}","starred_url":"https://api.github.com/users/jrgleason/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jrgleason/subscriptions","organizations_url":"https://api.github.com/users/jrgleason/orgs","repos_url":"https://api.github.com/users/jrgleason/repos","events_url":"https://api.github.com/users/jrgleason/events{/privacy}","received_events_url":"https://api.github.com/users/jrgleason/received_events","type":"User","site_admin":false},"created_at":"2016-10-17T22:48:12Z","updated_at":"2016-10-17T22:48:12Z","body":"Also I have the entries and plugins removed. I am using split files."}}
{"actor":{"display_login":"jrgleason"}}