Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Failed to load plugin 'vue' declared in 'CLIOptions': The argument 'filename' must be a file URL object, file URL string, or absolute path string. Received '' #72

Closed
M1CK431 opened this issue Aug 11, 2022 · 7 comments

Comments

@M1CK431
Copy link

M1CK431 commented Aug 11, 2022

Describe the bug
Can't format a document using CTRL+MAJ+I (aka document.action.format). However it works as expected while saving the file (despite the error message).

In output section, I have the following error:

Error: Failed to load plugin 'vue' 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 'vue' 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:1230:13)
	at Object.resolve (/home/me/Projects/myProject/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2325:16)
	at Object.ModuleResolver.resolve (/home/me/Projects/myProject/node_modules/@rushstack/eslint-patch/lib/modern-module-resolution.js:201:44)
	at ConfigArrayFactory._loadPlugin (/home/me/Projects/myProject/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3376:33)
	at ConfigArrayFactory._loadPlugin (/home/me/Projects/myProject/node_modules/@rushstack/eslint-patch/lib/modern-module-resolution.js:203:43)
	at /home/me/Projects/myProject/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3267:33
	at Array.reduce (<anonymous>)
	at ConfigArrayFactory._loadPlugins (/home/me/Projects/myProject/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3263:22)
	at ConfigArrayFactory._normalizeObjectConfigDataBody (/home/me/Projects/myProject/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3063:44)
	at _normalizeObjectConfigDataBody.next (<anonymous>)
	at ConfigArrayFactory._normalizeObjectConfigData (/home/me/Projects/myProject/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3003:20)
	at _normalizeObjectConfigData.next (<anonymous>)
	at ConfigArrayFactory.create (/home/me/Projects/myProject/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2798:16)
	at createCLIConfigArray (/home/me/Projects/myProject/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3608:47)
	at CascadingConfigArrayFactory.clearCache (/home/me/Projects/myProject/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3780:32)
	at new ESLint (/home/me/Projects/myProject/node_modules/eslint/lib/eslint/eslint.js:448:32)
	at Pge (/home/me/.vscode-oss/extensions/rvest.vs-code-prettier-eslint-5.0.4/dist/extension.js:180:69)
	at /home/me/.vscode-oss/extensions/rvest.vs-code-prettier-eslint-5.0.4/dist/extension.js:188:700
	at Lge (/home/me/.vscode-oss/extensions/rvest.vs-code-prettier-eslint-5.0.4/dist/extension.js:180:1439)
	at processTicksAndRejections (node:internal/process/task_queues:96:5)

The error occurs each time I press CTRL+MAJ+I and when I save the document. The document is formatted only when I save it.

To Reproduce
Steps to reproduce the behavior:

  1. In a vue 3 project (vite based), create a .vue file, then press CTRL+MAJ+I.
  2. The document will not be formatted and the error will occurred in the output section of "prettier eslint" extension.

Expected behavior
The document should be formatted and no error should appears in the output

Example Project
I'm very sorry but it happens in a closed source project of my company. I can't provide the source code.

Screenshots
Here is all extensions installed in vscode (dunno if it could be useful of not):
image

Also here is my vscode config:

{
    "git.alwaysShowStagedChangesResourceGroup": true,
    "prettier.eslintIntegration": true,
    "gitlens.views.repositories.location": "scm",
    "gitlens.views.fileHistory.location": "scm",
    "gitlens.views.lineHistory.location": "scm",
    "gitlens.views.compare.location": "scm",
    "gitlens.views.search.location": "scm",
    "telemetry.telemetryLevel": "off",
    "editor.tabSize": 2,
    "editor.multiCursorModifier": "ctrlCmd",
    "git.allowForcePush": true,
    "git.branchProtection": [
        "develop"
    ],
    "git.pruneOnFetch": true,
    "github.gitAuthentication": false,
    "html.format.wrapLineLength": 80,
    "vetur.useWorkspaceDependencies": true,
    "workbench.colorTheme": "Atom One Dark",
    "problems.showCurrentInStatus": true,
    "eslint.packageManager": "yarn",
    "javascript.format.semicolons": "remove",
    "typescript.format.semicolons": "remove",
    "typescript.surveys.enabled": false,
    "editor.rulers": [
    80
    ],
    "vetur.ignoreProjectWarning": true,
    "[vue]": {
        "editor.defaultFormatter": "rvest.vs-code-prettier-eslint"
    },
    "[javascript]": {
        "editor.defaultFormatter": "rvest.vs-code-prettier-eslint"
    },
    "workbench.tree.indent": 14,
    "atomKeymap.promptV3Features": true,
    "sortJSON.contextMenu": {
        "sortJSONReverse": false,
        "sortJSONKeyLength": false,
        "sortJSONKeyLengthReverse": false,
        "sortJSONAlphaNum": false,
        "sortJSONAlphaNumReverse": false,
        "sortJSONValues": false,
        "sortJSONValuesReverse": false,
        "sortJSONType": false,
        "sortJSONTypeReverse": false
    },
    "editor.autoClosingBrackets": "always",
    "editor.formatOnPaste": false,
    "editor.formatOnType": false,
    "editor.formatOnSave": true,
    "editor.formatOnSaveMode": "file",
    "[html]": {
        "editor.defaultFormatter": "rvest.vs-code-prettier-eslint"
    },
    "AllAutocomplete.cycleOpenDocumentsOnLaunch": true,
    "AllAutocomplete.maxItemsInSingleList": 9999
}

And finally the relevant part of my package.json:

{
  "name": "webapp",
  "version": "0.0.0",
  "scripts": {
    "dev": "vite",
    "build": "vite build",
    "preview": "vite preview --port 4173",
    "lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs --fix --ignore-path .gitignore"
  },
  "dependencies": {
    "@apollo/client": "^3.6.9",
    "@vue/apollo-option": "^4.0.0-alpha.20",
    "graphql": "^16.5.0",
    "graphql-tag": "^2.12.6",
    "vue": "^3.2.37",
    "vue-i18n": "^9.2.2",
    "vue-router": "^4.1.2"
  },
  "devDependencies": {
    "@rollup/plugin-graphql": "^1.1.0",
    "@rushstack/eslint-patch": "^1.1.0",
    "@vitejs/plugin-vue": "^3.0.1",
    "@vue/eslint-config-prettier": "^7.0.0",
    "autoprefixer": "^10.4.8",
    "eslint": "^8.5.0",
    "eslint-plugin-vue": "^9.0.0",
    "postcss": "^8.4.14",
    "prettier": "^2.5.1",
    "tailwindcss": "^3.1.7",
    "vite": "^3.0.1",
    "vite-svg-loader": "^3.4.0"
  }
}

Versions:

  • VS Code Prettier ESLint extension: 5.0.4
  • Visual Studio Code: 1.70.1
  • Node: 18.7.0
  • Package Manager: yarn 1.22.19
  • prettier: 2.7.1
  • eslint: 8.21.0

System Specifications:

  • OS: ArchLinux
  • Processor: Intel Core i7-8550U
  • RAM Size: 16 GB

Additional context
I have another project (closed source too) based on vue-cli which works perfectly with the same vscode configuration and the same eslint/prettier config and version. Also, in both project, vscode is started from a terminal directly in the root folder of the project (where stands .git folder) using code .. Is this issue related to vite based project? 🤔

@M1CK431
Copy link
Author

M1CK431 commented Aug 11, 2022

UPDATE: in fact, in a pure .js file, format failed also on save 😢

@idahogurl
Copy link
Owner

@M1CK431 This is an issue with the @rushstack/eslint-patch not with the extension or prettier-eslint. Other users have had the same issue with the@next/eslint-plugin-next which uses @rushstack/eslint-patch.
See #42

@M1CK431
Copy link
Author

M1CK431 commented Aug 11, 2022

Thanks a lot for explanation and sorry for the noise 😘

@mattbrannon
Copy link
Contributor

@M1CK431 If this is still an issue for you, one way to get around the problem is to patch it yourself.

Open the file ./node_modules/@rushstack/eslint-patch/lib/modern-module-resolution.js and near the bottom of the file, look for the line

return originalResolve.call(this, moduleName, ctx.filePath);

and change it to

return originalResolve.call(this, moduleName, ctx.filePath || relativeToPath);

Then run npx patch-package @rushstack/eslint-patch

Source

@M1CK431
Copy link
Author

M1CK431 commented Sep 15, 2022

For now, I have just commented // require("@rushstack/eslint-patch/modern-module-resolution"); in my index.cjs and everything works so... 🤷‍♂️

@bertho-zero
Copy link

@mattbrannon saved me !

Yarn berry allow yarn patch @rushstack/eslint-patch.

Anyone to make a PR on https://github.com/microsoft/rushstack/blob/a142f4608c1cf92fc937ff386d5db033412873ed/eslint/eslint-patch/src/modern-module-resolution.ts#L233-L241 ?

@ci-vamp
Copy link

ci-vamp commented Jul 5, 2023

FYI in case anyone comes across this - it is fixed. see this comment for details

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants