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

Dependency resolution error with short file name on Windows #19275

Closed
ayame113 opened this issue May 26, 2023 · 0 comments
Closed

Dependency resolution error with short file name on Windows #19275

ayame113 opened this issue May 26, 2023 · 0 comments

Comments

@ayame113
Copy link
Contributor

Please refer to denoland/fresh#471 (comment).

This bug is caused by a combination of the following three conditions.

  • cwd is set to a windows short pathname (using command prompt or cwd option of Deno.Command)
  • deno.json exists
  • There is an import-map with a relative path

How to reproduce the bug

Move to the Windows short file name (= 8.3 format) directory. (I had to use cmd instead of powershell for this.)

> dir /x
2023/05/26  15:32    <DIR>                       .
2023/05/09  08:52    <DIR>                       ..
2023/05/26  15:35    <DIR>          TESTDI~1     test dir # This means that the short filename alias for `test dir` is `TESTDI~1`.

> cd ../TESTDI~1

Create a file like this:

// deno.json
{
  "importMap": "./import-map.json"
}

// import-map.json
{
  "imports": {
    "@/": "./"
  }
}

// parent.ts
import "@/child.ts";
import "./child.ts";

// child.ts
console.log("hello from child.ts!");

Run deno info. Here the dependencies include two child.ts. I believe this is a bug.
Also, console.log is done twice when I run deno run.

> deno info parent.ts
local: C:\Users\ayame\work\TESTDI~1\parent.ts
emit: C:\Users\ayame\AppData\Local\deno\gen\file\C\Users\ayame\work\TESTDI~1\parent.ts.js
type: TypeScript
dependencies: 2 unique
size: 120B

file:///C:/Users/ayame/work/TESTDI~1/parent.ts (44B)
├── file:///C:/Users/ayame/work/test%20dir/child.ts (38B)
└── file:///C:/Users/ayame/work/TESTDI~1/child.ts (38B)

> deno run ./parent.ts
hello from child.ts!
hello from child.ts!

This is causing strange errors like the one described by denoland/fresh#471 (comment).

Another oddity about this bug is that if I remove the deno.json it works fine.
The result of deleting deno.json and running is below.

> deno info --import-map=import-map.json ./parent.ts
local: C:\Users\ayame\work\TESTDI~1\parent.ts
emit: C:\Users\ayame\AppData\Local\deno\gen\file\C\Users\ayame\work\TESTDI~1\parent.ts.js
type: TypeScript
dependencies: 1 unique
size: 82B

file:///C:/Users/ayame/work/TESTDI~1/parent.ts (44B)
├── file:///C:/Users/ayame/work/TESTDI~1/child.ts (38B)
└── file:///C:/Users/ayame/work/TESTDI~1/child.ts *

> deno run --import-map=import-map.json ./parent.ts
hello from child.ts!

I don't know how many people use Windows's short pathnames, but it's strange that the behavior changes depending on whether deno.json exists or not.

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

1 participant