ctrlplusb / react-universally

A starter kit for universal react applications.
MIT License
1.7k stars 244 forks source link

Unable to use eslint-import-resolver-webpack with webpackConfigFactory #481

Closed rckahale closed 7 years ago

rckahale commented 7 years ago

I have some alias in my webpack config. I want to fix eslint errors arising out of it. I followed this, but I could not find webpack config json to be applied as react-universally uses config generated from factory. AFAIK, js imports and function calls can't be made in eslintrc file. How can I fix these errors?

diondirza commented 7 years ago

You can make separate file e.g eslint-import-resolver.js which reflect webpack config just contain resolve alias value like sample below

module.exports = {
  resolve: {
    extensions: ['.js', '.jsx', '.scss'],
    modules: [path.resolve(appRootDir.get(), './src'), path.resolve(appRootDir.get(), './node_modules')],
    alias: {
      TweenLite: 'gsap/src/uncompressed/TweenLite',
      TimelineLite: 'gsap/src/uncompressed/TimelineLite',
    },
  },
};

Then change your .eslintrc config path of import rules to point to this file.

rckahale commented 7 years ago

Thanks for the quick response Dion! I tried above steps, but still found same errors. I think the eslint-import-resolver-webpack is expecting entire config object along with resolve & other keys. I also tried with

"settings": {
    "import/resolver": {
      "webpack": {
        "config": {
          "resolve" : "eslint-import-resolver.js"
        }
      }
    }
  }
diondirza commented 7 years ago

It's should be config.path instead of config.resolve.

rckahale commented 7 years ago

No luck with config.path However, i found an alternative. I shifted my alias into babelrc from webpack's configFactory. The modules which helped me for the cause are babel-plugin-module-resolver and eslint-import-resolver-babel-module