Skip to content

Call to enhanced-resolve converts # in paths to \0#, which crashes eslint-plugin-import #208

Closed
@ashmind

Description

@ashmind

Overview

When a path includes #, it seems that enhanced-resolve replaces it with \0# (https://github.com/webpack/enhanced-resolve#escaping). Unfortunately further up this causes a failure in eslint-plugin-import:

TypeError [ERR_INVALID_ARG_VALUE]: The argument 'path' must be a string or Uint8Array without null bytes. Received 'c:\\Development\\SharpLab\\source\\\x00#external\\mirrorsharp-codemirror-6-preview\\WebAssets\\node_modules\\@codemirror\\comma...
Occurred while linting c:\Development\SharpLab\source\#external\mirrorsharp-codemirror-6-preview\WebAssets\src\codemirror\create.ts:1
Rule: "import/namespace"
    at Object.statSync (node:fs:1581:10)
    at Function.ExportMap.for (c:\Development\SharpLab\source\#external\mirrorsharp-codemirror-6-preview\WebAssets\node_modules\eslint-plugin-import\lib\ExportMap.js:792:67)
    at Function.ExportMap.get (c:\Development\SharpLab\source\#external\mirrorsharp-codemirror-6-preview\WebAssets\node_modules\eslint-plugin-import\lib\ExportMap.js:791:463)
    at processBodyStatement (c:\Development\SharpLab\source\#external\mirrorsharp-codemirror-6-preview\WebAssets\node_modules\eslint-plugin-import\lib\rules\namespace.js:11:40)
    at c:\Development\SharpLab\source\#external\mirrorsharp-codemirror-6-preview\WebAssets\node_modules\eslint-plugin-import\lib\rules\namespace.js:82:47
    at Array.forEach (<anonymous>)
    at Program (c:\Development\SharpLab\source\#external\mirrorsharp-codemirror-6-preview\WebAssets\node_modules\eslint-plugin-import\lib\rules\namespace.js:82:18)
    at ruleErrorHandler (c:\Development\SharpLab\source\#external\mirrorsharp-codemirror-6-preview\WebAssets\node_modules\eslint\lib\linter\linter.js:1115:28)
    at c:\Development\SharpLab\source\#external\mirrorsharp-codemirror-6-preview\WebAssets\node_modules\eslint\lib\linter\safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
task ts:eslint failed:
Error: Command failed with exit code 2: eslint ./src --max-warnings 0 --ext .js,.jsx,.ts,.tsx
    at makeError (c:\Development\SharpLab\source\#external\mirrorsharp-codemirror-6-preview\WebAssets\node_modules\oldowan\node_modules\execa\lib\error.js:59:11)
    at handlePromise (c:\Development\SharpLab\source\#external\mirrorsharp-codemirror-6-preview\WebAssets\node_modules\oldowan\node_modules\execa\index.js:114:26)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async exec (c:\Development\SharpLab\source\#external\mirrorsharp-codemirror-6-preview\WebAssets\node_modules\oldowan\dist\index.js:53:5)
    at async task.run (c:\Development\SharpLab\source\#external\mirrorsharp-codemirror-6-preview\WebAssets\node_modules\oldowan\dist\index.js:74:13)
    at async file:///c:/Development/SharpLab/source/%23external/mirrorsharp-codemirror-6-preview/WebAssets/build.ts:74:5
    at async Object.task.run (c:\Development\SharpLab\source\#external\mirrorsharp-codemirror-6-preview\WebAssets\node_modules\oldowan\dist\index.js:74:13)
    at async build (c:\Development\SharpLab\source\#external\mirrorsharp-codemirror-6-preview\WebAssets\node_modules\oldowan\dist\index.js:107:9) {
  shortMessage: 'Command failed with exit code 2: eslint ./src --max-warnings 0 --ext .js,.jsx,.ts,.tsx',
  command: 'eslint ./src --max-warnings 0 --ext .js,.jsx,.ts,.tsx',
  exitCode: 2,
  signal: undefined,
  signalDescription: undefined,
  stdout: undefined,
  stderr: undefined,
  failed: true,
  timedOut: false,
  isCanceled: false,
  killed: false
}

Why this library?

I could report this to enhanced-resolve, but their \0 escape seems to be well documented and by design. Happy to report there if you think that's the best option.

I could report this to eslint-plugin-import, however the problem depends on details resolver implementation, and eslint-plugin-import seems resolver-agnostic.

Proposed solution

Path returned by enhanced-resolve can be post-processed to replace \0# with #, which is the correct representation of the filesystem path.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions