Marko Gresak
Marko Gresak

Reputation: 8207

Karma webpack Error: no such file or directory /_karma_webpack_/

I am using script

// src/test-index.js
const context = require.context('./src', true, /-test\.js$/)
context.keys().forEach(context)

And I keep running into error

> NODE_ENV=test karma start --single-run --no-auto-watch
...
ERROR [karma]: { Error: no such file or directory
    at MemoryFileSystem.readFileSync (PROJECT_ROOT/node_modules/memory-fs/lib/MemoryFileSystem.js:107:10)
    at MemoryFileSystem.readFile (PROJECT_ROOT/node_modules/memory-fs/lib/MemoryFileSystem.js:297:21)
    at doRead (PROJECT_ROOT/node_modules/karma-webpack/index.js:156:26)
    at Plugin.readFile (PROJECT_ROOT/node_modules/karma-webpack/index.js:160:3)
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9)
  code: 'ENOENT',
  errno: 34,
  message: 'no such file or directory',
  path: '/_karma_webpack_/test-index.js' }
Error: no such file or directory
    at MemoryFileSystem.readFileSync (PROJECT_ROOT/node_modules/memory-fs/lib/MemoryFileSystem.js:107:10)
    at MemoryFileSystem.readFile (PROJECT_ROOT/node_modules/memory-fs/lib/MemoryFileSystem.js:297:21)
    at doRead (PROJECT_ROOT/node_modules/karma-webpack/index.js:156:26)
    at Plugin.readFile (PROJECT_ROOT/node_modules/karma-webpack/index.js:160:3)
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9)

Here is link to gist with my karma.conf.js and webpack.config.js. I've left other files out since these (plus the test-index.js above) are the only files involved in current process.

Node v6.2.0, npm v3.8.9 (installed via nvm). All dependencies were installed in last few hours so I am using latest versions.

Any ideas about what could be wrong or what else could I try?

Upvotes: 1

Views: 2838

Answers (1)

Marko Gresak
Marko Gresak

Reputation: 8207

The issue was with trying to reuse my original config for karma webpack config key.

I've solved the issue by changing karma config to:

webpack: {
  module: {
    loaders: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        loader: 'babel'
      }
    ]
  },
  externals: {
    cheerio: 'window',
    'react/addons': true,
    'react/lib/ExecutionEnvironment': true,
    'react/lib/ReactContext': true
  },
  node: {
    fs: 'empty'
  }
},

What's important here is module object and node object (to prevent Cannot find module "fs" errors). The externals part is specific to enzyme and is was copied from their Enzyme + Karma + Webpack guide. Also specific to how enzyme is working, note that there is no explicit resolve declaration since webpack automatically adds '.js' and '.json', since enzyme is internally requiring both files. An alternative would be to explicitly declare json loader.

Upvotes: 1

Related Questions