Skip to content

Better report success when nodejs.exe creation fails #303

Closed

Description

@bersbersbers

Related to #180, I see this in my console:

C:\Users\bers>nodeenv x
 * Install prebuilt node (17.8.0) ..... done.
You do not have sufficient privilege to perform this operation.
You do not have sufficient privilege to perform this operation.
Error: Failed to create nodejs.exe link

C:\Users\bers>nodeenv x
 * Environment already exists: x

To me, this looks like the first operation failed, and I only see that upon trying again.

(I have the impression that this hinders pyright startup on my system, but I am not experienced enough with either to say if that is in fact working as intended or not.)

Activity

  1. ekalinin commented on Sep 19, 2026

    @ekalinin
    Owner

    Digging into this while closing #190, which quotes the same failure plus a second flavour of it. Some findings that might help.

    Why the message is printed twice

    callit prints every line of the child's output as it reads it, and then, if the exit code is nonzero, prints the whole buffer again before raising:

            all_output.append(line)
            if show_stdout:
                logger.info(line)
        proc.wait()
    
        # error handler
        if proc.returncode:
            if show_stdout:
                for s in all_output:
                    logger.critical(s)
            raise OSError(...)

    install_activate calls it with show_stdout=True, so mklink's single line of output is echoed twice. That is the duplication you are seeing, not two separate attempts.

    The OSError is then caught and turned into logger.error('Error: Failed to create nodejs.exe link'). Per #180 this is intentionally non-fatal, but between the doubled output and the Error: prefix at ERROR level it reads like the run failed, while nodeenv in fact exits 0 and the env is usable.

    A second way the same call fails

    #190 hit the same code path with a different message:

    Invalid switch - "Temp".
    Invalid switch - "Temp".
    Error: Failed to create nodejs.exe link
    

    That one is a quoting bug. The call is

    callit(['mklink', shim_nodejs, 'node.exe'], True, True)

    and with in_shell=True callit does a bare cmd = ' '.join(cmd). The quoting loop above it only builds cmd_desc for the debug log, it is not applied to what actually runs. So if the env path was given with forward slashes (nodeenv C:/Temp/.../nenv), cmd parses /Temp as a switch. An env path containing a space breaks the same way.

    Suggestion

    mklink is a cmd builtin, which is the only reason this needs a shell at all. Python can do it directly, the way the non-Windows branch already does:

        if not os.path.exists(shim_nodejs):
            if is_WIN:
                try:
                    os.symlink('node.exe', shim_nodejs)
                except OSError:
                    try:
                        os.link(join(bin_dir, 'node.exe'), shim_nodejs)
                    except OSError:
                        logger.warning('Could not create the nodejs.exe link; '
                                       'this is harmless unless something on your '
                                       'system invokes node as "nodejs"')
            else:
                os.symlink('node', shim_nodejs)

    That gets rid of the shell entirely, so the quoting bug and both duplicated lines go away. os.symlink also succeeds without elevation when Developer Mode is on (documented for 3.8+), and the hard link needs no privilege at all, so the common case in this report stops failing rather than just reporting more nicely. The remaining message is a warning that says what the user loses, which I think is what you were asking for here.

  2. added 2 commits that reference this issue on Sep 26, 2026
    152cd3d
    fd19956
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions