prettier / prettier-eslint-cli

CLI for prettier-eslint
https://npm.im/prettier-eslint-cli
MIT License
539 stars 85 forks source link

incompatibility with Next eslint config #434

Closed barroudjo closed 2 years ago

barroudjo commented 2 years ago

Relevant code/config.

\\ .eslintrc.js
module.exports = {
  extends: ['next', 'prettier'],
};

What you did: I installed the latest version of prettier-eslint-cli (@6.0.1) I launched it on a project using the above .eslintrc.js with the command npx prettier-eslint "src/**/*.js"

What happened:

prettier-eslint [ERROR]: eslint fix failed due to an eslint error
prettier-eslint-cli [ERROR]: There was an error formatting "/home/linuxpoutous/Ekwateur/edito-front/src/prismic-template/content/InteractiveBills/EnergyButton/EnergyButton.js": 
    TypeError [ERR_INVALID_ARG_VALUE]: Failed to load plugin 'react-hooks' declared in 'CLIOptions': The argument 'filename' must be a file URL object, file URL string, or absolute path string. Received ''
        at new NodeError (node:internal/errors:371:5)
        at createRequire (node:internal/modules/cjs/loader:1218:13)
        at Object.resolve (/home/linuxpoutous/Ekwateur/edito-front/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2325:16)
        at Object.ModuleResolver.resolve (/home/linuxpoutous/Ekwateur/edito-front/node_modules/@rushstack/eslint-patch/lib/modern-module-resolution.js:201:44)
        at ConfigArrayFactory._loadPlugin (/home/linuxpoutous/Ekwateur/edito-front/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3376:33)
        at ConfigArrayFactory._loadPlugin (/home/linuxpoutous/Ekwateur/edito-front/node_modules/@rushstack/eslint-patch/lib/modern-module-resolution.js:203:43)
        at /home/linuxpoutous/Ekwateur/edito-front/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3267:33
        at Array.reduce (<anonymous>)
        at ConfigArrayFactory._loadPlugins (/home/linuxpoutous/Ekwateur/edito-front/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3263:22)
        at ConfigArrayFactory._normalizeObjectConfigDataBody (/home/linuxpoutous/Ekwateur/edito-front/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3063:44)
prettier-eslint [ERROR]: eslint fix failed due to an eslint error
prettier-eslint-cli [ERROR]: There was an error formatting "/home/linuxpoutous/Ekwateur/edito-front/src/prismic-template/content/InteractiveBills/EnergyButton/EnergyButton.styles.js": 
    TypeError [ERR_INVALID_ARG_VALUE]: Failed to load plugin 'react-hooks' declared in 'CLIOptions': The argument 'filename' must be a file URL object, file URL string, or absolute path string. Received ''

Problem description:

My guess is that it is because the next eslint config is using @rushstack/eslint-patch which changes the way plugins are loaded. I found out about this issue when using vs-code-prettier-eslint, and raised an issue for this there (https://github.com/idahogurl/vs-code-prettier-eslint/issues/42), but since the problem lies with prettier-eslint, here is the relevant issue !

ownchoice commented 2 years ago

Same problem over here.

Tried installing several packages for the ESLint plugins (not necessary when executing eslint and next lint) but still getting the same error, just with a different plugin (@typescript-eslint):

Error: Failed to load plugin '@typescript-eslint' declared in 'CLIOptions': The argument 'filename' must be a file URL object, file URL string, or absolute path string. Received '' 
TypeError: Failed to load plugin '@typescript-eslint' declared in 'CLIOptions': The argument 'filename' must be a file URL object, file URL string, or absolute path string. Received ''
    at new NodeError (node:internal/errors:371:5)
    at createRequire (node:internal/modules/cjs/loader:1277:13)
    at Object.resolve (d:\git\subfolder\project\web_prod\node_modules\@eslint\eslintrc\dist\eslintrc.cjs:2325:16)
    at Object.ModuleResolver.resolve (d:\git\subfolder\project\web_prod\node_modules\@rushstack\eslint-patch\lib\modern-module-resolution.js:201:44)
    at ConfigArrayFactory._loadPlugin (d:\git\subfolder\project\web_prod\node_modules\@eslint\eslintrc\dist\eslintrc.cjs:3376:33)
    at ConfigArrayFactory._loadPlugin (d:\git\subfolder\project\web_prod\node_modules\@rushstack\eslint-patch\lib\modern-module-resolution.js:203:43)
    at d:\git\subfolder\project\web_prod\node_modules\@eslint\eslintrc\dist\eslintrc.cjs:3267:33
    at Array.reduce (<anonymous>)
    at ConfigArrayFactory._loadPlugins (d:\git\subfolder\project\web_prod\node_modules\@eslint\eslintrc\dist\eslintrc.cjs:3263:22)
    at ConfigArrayFactory._normalizeObjectConfigDataBody (d:\git\subfolder\project\web_prod\node_modules\@eslint\eslintrc\dist\eslintrc.cjs:3063:44)
    at _normalizeObjectConfigDataBody.next (<anonymous>)
    at ConfigArrayFactory._normalizeObjectConfigData (d:\git\subfolder\project\web_prod\node_modules\@eslint\eslintrc\dist\eslintrc.cjs:3003:20)
    at _normalizeObjectConfigData.next (<anonymous>)
    at ConfigArrayFactory.create (d:\git\subfolder\project\web_prod\node_modules\@eslint\eslintrc\dist\eslintrc.cjs:2798:16)
    at createCLIConfigArray (d:\git\subfolder\project\web_prod\node_modules\@eslint\eslintrc\dist\eslintrc.cjs:3608:47)
    at CascadingConfigArrayFactory.clearCache (d:\git\subfolder\project\web_prod\node_modules\@eslint\eslintrc\dist\eslintrc.cjs:3780:32)
    at new ESLint (d:\git\subfolder\project\web_prod\node_modules\eslint\lib\eslint\eslint.js:448:32)
    at Pge (c:\Users\onlyme\.vscode\extensions\rvest.vs-code-prettier-eslint-5.0.1\dist\extension.js:180:69)
    at c:\Users\onlyme\.vscode\extensions\rvest.vs-code-prettier-eslint-5.0.1\dist\extension.js:188:700
    at Lge (c:\Users\onlyme\.vscode\extensions\rvest.vs-code-prettier-eslint-5.0.1\dist\extension.js:180:1439)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
barroudjo commented 2 years ago

Same issue as this one: https://github.com/prettier/prettier-eslint-cli/issues/426

barroudjo commented 2 years ago

Sorry to bump this issue, but is this on your radar ? Do you plan to solve it, or is this a deeper issue, that should rather be fixed in @rushstack/eslint-patch ?

JounQin commented 2 years ago

You should provide a runnable minimal reproduction first.

mattbrannon commented 2 years ago

You should provide a runnable minimal reproduction first.

@JounQin runnable minimal reproduction.

JounQin commented 2 years ago

You should provide a runnable minimal reproduction first.

@JounQin runnable minimal reproduction.

Thanks for reproduction first, but can you please clarify what command to reproduce the issue, what's the problem and what is expected?

mattbrannon commented 2 years ago

@JounQin Sure thing. In the example, the file at pages/index.js has this code with a long string of text:

export default function Home() {
  return (
    <p>
      Lorem, ipsum dolor sit amet consectetur adipisicing elit. Veniam illum placeat ratione consequuntur dolor ea? Quas explicabo minus voluptate, laudantium aliquam accusamus aperiam aliquid nisi, iste adipisci placeat, repudiandae cumque.
    </p>
  )
}

Problem: Running prettier-eslint on this file throws an error:

TypeError [ERR_INVALID_ARG_VALUE]: Failed to load plugin 'react-hooks' declared in 'CLIOptions': The argument 'filename' must be a file URL object, file URL string, or absolute path string. Received ''

Expected: prettier-eslint should format the file without throwing an error.

Steps to reproduce:

The eslint config is the default provided by Next.js. If the config is removed, prettier-eslint formats the code as expected.

JounQin commented 2 years ago

@mattbrannon Sorry I was a bit busy these days, hope I can find some free time to invest today.

JounQin commented 2 years ago
image

@mattbrannon I believe this is caused by @rushstack/eslint-patch which is used by eslint-config-next.

A quick fix could be return originalResolve.call(this, moduleName, ctx.filePath || relativeToPath)

barroudjo commented 2 years ago

Ok, I guess we can try to propose a PR with this fix to rushstack/eslint-patch. Thanks for investigating !

ci-vamp commented 1 year ago

FYI this has been merged into eslint-patch, however the nextjs eslint extension is not using the latest version of the package. see this comment for how to override it