Bug: All ESLint 8 commands fail if the project path contains URL-encoded characters
See original GitHub issueEnvironment
Node version: 14.18.2 npm version: 6.14.15 Local ESLint version: 8.12.0 Global ESLint version: none Operating System: Darwin 20.6.0 (macOS Big Sur)
What parser are you using?
What did you do?
Try to run any ESLint command in a project path with a URL encoded character, such as /my%2Fproject/yarn eslint --env-info
.
What did you expect to happen?
Command would succeed with the expected output, such as:
/Users/myuser/my%2Fproject/node_modules/.bin/eslint --debug --env-info
eslint:cli CLI args: [ '--debug', '--env-info' ] +0ms
Environment Info:
Node version: v14.18.2
npm version: v6.14.15
Local ESLint version: v8.12.0 (Currently used)
Global ESLint version: Not found
Operating System: darwin 20.6.0
What actually happened?
Example
A project with eslint@8.12.0
installed is in the following path that includes a URL-encoded slash:
/Users/myuser/my%2Fproject
Run any ESLint command, such as --env-info
and it fails with the following:
/Users/myuser/my%2Fproject/node_modules/.bin/eslint --debug --env-info
Oops! Something went wrong! :(
ESLint: 8.12.0
TypeError [ERR_INVALID_ARG_VALUE]: The argument 'filename' must be a file URL object, file URL string, or absolute path string. Received 'file:///Users/d108059/Development/tmp/my%2Fproject/node_modules/@eslint/eslintrc/dist/eslintrc.cjs'
at new NodeError (internal/errors.js:322:7)
at Function.createRequire (internal/modules/cjs/loader.js:1182:13)
at Object.<anonymous> (/Users/d108059/Development/tmp/my%2Fproject/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2383:26)
at Module._compile (/Users/d108059/Development/tmp/my%2Fproject/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (/Users/d108059/Development/tmp/my%2Fproject/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
at Object.<anonymous> (/Users/d108059/Development/tmp/my%2Fproject/node_modules/eslint/lib/cli-engine/cli-engine.js:33:5)
error Command failed with exit code 2.
Participation
- I am willing to submit a pull request for this issue.
Additional comments
Prior versions of ESLint, such as 7.32.0
, work fine with these paths. For example, this works fine:
/Users/myuser/my%2Fproject/node_modules/.bin/eslint --debug --env-info
eslint:cli CLI args: [ '--debug', '--env-info' ] +0ms
Environment Info:
Node version: v14.18.2
npm version: v6.14.15
Local ESLint version: v7.32.0 (Currently used)
Global ESLint version: Not found
Operating System: darwin 20.6.0
Issue Analytics
- State:
- Created a year ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Request path contains unescaped characters, how can I fix ...
I was getting this error while trying to hit Elasticsearch's API. ... Switching to all English characters fixed the issue.
Read more >Changelog - Cypress Documentation
Fixes an issue where usage of the --spec option would result in no specs found if the absolute project path included glob pattern...
Read more >eslint | Yarn - Package Manager
A bug fix to the CLI or core (including formatters). Improvements to documentation. Non-user-facing changes such as refactoring code, adding, deleting, or ...
Read more >Changelog - Karma test runner
cli: Karma is more strict and will error out if unknown option or ... Allow karma to run in project which path contains...
Read more >Error when builden apk - Unity Forum
Hello, I get some errors when I try to build an apk from a proyect I made and i don't ... Your project...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Looking at the line
/@eslint/eslintrc/dist/eslintrc.cjs:2383:26
hinted by the stack trace, I can find this code:You can see the whole file here: https://unpkg.com/@eslint/eslintrc@1.2.1/dist/eslintrc.cjs
The corresponding source code is this harmless-looking line in eslintrc:
which can be found here: https://github.com/eslint/eslintrc/blob/9b719813fc6f023b722168a4f67d895106e875ce/lib/config-array-factory.js#L58
From what I can tell, the generated code is trying to create a file URL from
__filename
, but doing so in a very error-prone way:'file:' + __filename
rather than using the builtin Node functionpathToFileURL
. The resulting URL will contain an escaped slash (%2F
) rather than the proper escape sequence for “%2F” (%252F
).This is not a bug in ESLint, but rather an issue with the build tools used in eslintrc, most probably Rollup.
Thanks all for the quick response! ❤️