VSCode gives Node.js "open EISDIR" error when opening file from REPL

Several months ago, I started getting an error when I use control+q to open a location in a stack trace or method list after entering an index into that list on the REPL any time I attempt to open a file from the REPL while ENV["EDITOR"] = "code". The error I get is the following (printed at the REPL):

node:net:413
      throw errnoException(err, 'open');
      ^

Error: open EISDIR
    at new Socket (node:net:413:13)
    at createWritableStdioStream (node:internal/bootstrap/switches/is_main_thread:78:18)
    at process.getStderr [as stderr] (node:internal/bootstrap/switches/is_main_thread:170:12)
    at console.get (node:internal/console/constructor:220:44)
    at console.value (node:internal/console/constructor:347:50)
    at console.warn (node:internal/console/constructor:382:61)
    at Object.h [as onError] (C:\Users\mikm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\cli.js:1:7727)
    at _.onError (C:\Users\mikm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\cli.js:1:12590)
    at h._onLoadError (C:\Users\mikm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\cli.js:3:7877)
    at l (C:\Users\mikm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\cli.js:3:9082)
    at Object.errorback (C:\Users\mikm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\cli.js:3:9457)
    at d.triggerErrorback (C:\Users\mikm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\cli.js:1:13508)
    at C:\Users\mikm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\cli.js:1:13259
    at i.load (C:\Users\mikm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\cli.js:2:1654)
    at d.load (C:\Users\mikm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\cli.js:1:13214)
    at l (C:\Users\mikm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\cli.js:3:9338)
    at Object.errorback (C:\Users\mikm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\cli.js:3:9457)
    at d.triggerErrorback (C:\Users\mikm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\cli.js:1:13508)
    at C:\Users\mikm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\cli.js:1:13259
    at i.load (C:\Users\mikm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\cli.js:2:1654)
    at d.load (C:\Users\mikm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\cli.js:1:13214)
    at l (C:\Users\mikm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\cli.js:3:9338)
    at h._loadModule (C:\Users\mikm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\cli.js:3:9466)
    at h._resolve (C:\Users\mikm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\cli.js:4:452)
    at h.defineModule (C:\Users\mikm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\cli.js:3:5561)
    at _ (C:\Users\mikm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\cli.js:4:1741)
    at m (C:\Users\mikm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\cli.js:2:2448)
    at Object.<anonymous> (C:\Users\mikm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\code\node\cli.js:31:28)
    at Object.<anonymous> (C:\Users\mikm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\code\node\cli.js:31:27732)
    at i._createAndEvalScript (C:\Users\mikm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\cli.js:2:2492)
    at C:\Users\mikm\AppData\Local\Programs\Microsoft VS Code\resources\app\out\cli.js:2:2133
    at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3) {
  errno: -4068,
  code: 'EISDIR',
  syscall: 'open'
}

Node.js v18.15.0

As best I can tell from reading online, EISDIR is thrown when Node.js intends to open a file but receives a directory.

The issue is resolved and the file opens successfully with my environment’s EDITOR=vim or another editor, but I’m hoping to get this working again with my preferred editor code. I can call code --goto ~/julia-1.10.0/share/julia/base/math.jl:50 and VSCode successfully opens the specified file to the requested line number, so it (naively) seems that something is wrong in the Julia interface to it. My VS Code installation affirms it is up to date. Julia is installed and run from a WSL Ubuntu install on a Windows 10 machine.

This functionality had worked on this machine for years but no longer does. I wish I remembered whether this started failing after a VS Code or Julia update, but I don’t. Does anyone have a suggestion with how to resolve this?

I’ll add that the same issue arises with a use of @edit, such as @edit exp(1.0). The issue occurs when running Julia from a standalone terminal. @edit works properly when running from a REPL within a terminal hosted within VSCode (presumably ^q would work except that it snags on a VSCode shortcut).

In what should have been no surprise, this error occurs when attempting to edit a file directly from the REPL, such as edit("path/to/file.jl"). Special modes of opening specific methods are irrelevant.

You might want to look closely at your vscode settings.

This SO post suggests it has to do with confusion brtween opening a directory or file:

Perhaps there is some setting the Julia environment which is messed up?

1 Like

Thanks. This didn’t directly help me, but it led me down the right rabbit hole. There’s some issue with redirecting stdout via pipeline when run from a standalone terminal (but not a VS Code terminal).

I opened `edit` with VS Code from a standalone terminal · Issue #53321 · JuliaLang/julia · GitHub with more info.

I’ve managed to sidestep this issue in the meantime by adding the following to my startup.jl:

# workaround for editor interaction issue https://github.com/JuliaLang/julia/issues/53321
atreplinit() do _
    InteractiveUtils.define_editor(["code", "code-insiders"]; wait=true) do cmd, path, line, column
        `$cmd -g $path:$line:$column`
    end
end

This doesn’t seem like the proper fix, but it’s working for me for now while the above-linked issue remains open.