eslint-webpack-plugin icon indicating copy to clipboard operation
eslint-webpack-plugin copied to clipboard

Error if package.json is not in parent directory to the linted code

Open trumko opened this issue 3 years ago • 0 comments
trafficstars

After updating eslint-plugin-import from 2.22.1 to 2.23.0 or higher the eslint-plugin-import breaks with warning:

ERROR in [eslint] The "path" argument must be of type string. Received null

After some investigation it looks like the reason is in the file structure when package.json file is not in the parent directory to the linted code:

myProject
├── build
  ├──  node_modules 
  ├──  package.json # is not in the parent directory to  source folder
  └──  [webpack.config.js, .eslintrc.js and other config files]
└── source
  └── modules #.js files, which should be linted

Interestingly, when I create a package.json file (which contains only empty {}) in the myProject folder, everything works as expected.

I just created minimal reproduction:

  1. Download repo
  2. Go to /build folder
  3. Run npm install
  4. Run npm start

You should see the next error:

ERROR in [eslint] The "path" argument must be of type string. Received null
Occurred while linting [folder]\webpack-boilerplate-master\app\index.js:1
Rule: "import/no-extraneous-dependencies"

Is there any solution how to make it work correctly with a similar file structure? I created a similar issue in eslint-plugin-import repository, but I was told that this issue is out of the scope of eslint-plugin-import plugin.

trumko avatar Aug 05 '22 07:08 trumko