codymikol / karma-webpack

Karma webpack Middleware
MIT License
830 stars 222 forks source link

Webpacker looks up webpacker.yml relative to karma.conf.js's directory #437

Closed dexterleng closed 4 years ago

dexterleng commented 4 years ago

I have karma.conf.js file in app/assets/javascripts/v3/karma.conf.js.

My webpacker.yml is in config/webpacker.yml.

Webpack config is in config/webpack/test.js.

Karma Config imports webpack config:

const webpackConfig = require('../../../../config/webpack/test');

module.exports = function(config) {
  config.set({
     ....
     webpack: webpackConfig
     ....
   })
}

This results in webpacker looking up webpack.yml relative to karma.conf.js location which throws a file not found error:

$ karma start --single-run
06 04 2020 15:07:32.509:ERROR [config]: Invalid config file!
  Error: ENOENT: no such file or directory, open '/Users/ts-dexter.leng/projects/cms/app/assets/javascripts/v3/config/webpacker.yml'
    at Object.fs.openSync (fs.js:646:18)
    at fs.readFileSync (fs.js:551:33)
    at Object.<anonymous> (/Users/ts-dexter.leng/projects/cms/node_modules/@rails/webpacker/package/env.js:12:25)
    at Module._compile (module.js:653:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Module.require (module.js:597:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/ts-dexter.leng/projects/cms/node_modules/@rails/webpacker/package/config.js:6:22)
    at Module._compile (module.js:653:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
error Command failed with exit code 1.

The error seems to have to do with how webpacker resolves paths in env.js

dexterleng commented 4 years ago

This seems to be a webpacker issue.