Skip to content

[BUG] Invalid Path on UI Scan Endpoint - Windows  #42

Open
@emmanuel39hanks

Description

@emmanuel39hanks

Description

When running the napi ui command in a project, the /api/scan endpoint fails with an Invalid file path error on Windows. The issue occurs because the entrypoint path from the .napirc configuration file is passed as a Windows-style path (e.g., C:\\Users\\emmanuel\\...) to the endpoint.

This bug prevents the napi ui visualizer from scanning the entry point and displaying the codebase structure, making the feature unusable on Windows.

Expected Behavior

The /api/scan endpoint should correctly process the entrypoint path, regardless of whether it’s in Windows-style or Unix-style format, and return a valid response.

Actual Behavior

The /api/scan endpoint fails with the following response:

[
  {
    "code": "custom",
    "message": "Invalid file path",
    "path": ["entrypointPath"]
  }
]

Possible Fix

Normalize file paths to handle both Windows-style (C:\...) and Unix-style (/...) paths.
Use a library like path from Node.js to ensure consistent path handling.

Steps to Reproduce

  1. On a Windows environment create a .napirc file with the following configuration:
{
  "entrypoint": "src/index.js",
  "out": "napi_dist"
}
  1. Run the command:
napi ui
  1. Observe the generated config (e.g., http://localhost:3000/api/config) with Windows-style paths:
{
  "entrypoint": "C:\\Users\\emmanuel\\opensource\\napi\\examples\\express\\src\\index.js",
  "out": "C:\\Users\\emmanuel\\opensource\\napi\\examples\\express\\napi_dist"
}
  1. Check the /api/scan endpoint and see the Invalid file path error.

Context

This bug blocks the ability to use then napi ui command on Windows. It affects Windows developers trying to scan their entrypoint and view their codebase in the visualizer.

Your Environment

  • Version used: napi v0.0.19
  • NodeJS Version: v20.11.0
  • Operating System: Windows 11

Config File

Paste your .napirc below

{
  "entrypoint": "src/index.js",
  "out": "napi_dist"
}

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions