eslint-plugin-require-path-exists icon indicating copy to clipboard operation
eslint-plugin-require-path-exists copied to clipboard

Can't find webpack.config.js on Windows

Open RinkAttendant6 opened this issue 7 years ago • 1 comments

The plugin doesn't seem to build the path correctly on Windows. The exact same code works fine on Linux.

.eslintrc.yaml

---
root: true
env:
    browser: true
    node: true
    es6: true
parserOptions:
    ecmaVersion: 8
    sourceType: module
plugins:
    - require-path-exists
extends:
    - eslint:recommended
    - plugin:require-path-exists/recommended
rules:
    require-path-exists/exists:
        - error
        -
            webpackConfigPath: webpack.config.js

webpack.config.js

module.exports = {
    resolve: {
        alias: {
            '@includes': require('path').resolve(__dirname, 'public', 'global', 'resources', 'js')
        }
    }
};

Error

grunt eslint gives me this output:

Warning: Error while loading rule 'require-path-exists/exists': Cannot load Webpack config: Cannot find module 'Z:GitHubProject1webpack.config.js' Use --force to continue.

RinkAttendant6 avatar Jul 08 '17 03:07 RinkAttendant6

This is happening because when a windows path is used in a string, the backslashes have to be escaped. I have found a solution for that.

Add a check to escape backslashes only on windows.

In the file eslint-plugin-require-path-exists/src/exists.js in line 19 this lines have to be added.

if (process.platform === "win32") {
    pathname = pathname.replace(/\\/g, "\\\\");
  }

There will be also necessary to change pathname from const to let, because now we are going to modify that. The final code will be so:

  let pathname = path.resolve(fromDir);
  if (process.platform === "win32") {
    pathname = pathname.replace(/\\/g, "\\\\");
  }

  if (webpackConfigCache[pathname]) {
    return webpackConfigCache[pathname];
  }

I hope this solution, or other could be added as soon as possible.

josejamart avatar Feb 14 '18 10:02 josejamart