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

npm 命令可以用,node 命令不能使用 #70

Closed
Yfkj01 opened this issue Mar 13, 2024 · 10 comments
Closed

npm 命令可以用,node 命令不能使用 #70

Yfkj01 opened this issue Mar 13, 2024 · 10 comments
Labels

Comments

@Yfkj01
Copy link

Yfkj01 commented Mar 13, 2024

image
nvm-desktop 3.2.0 版本
win 10 系统

@1111mp
Copy link
Owner

1111mp commented Mar 13, 2024

这个目录下应该会有一个node.exe文件的,方便告知一下该文件不存在的原因吗(自己手动删除了或者更新新版本之后就这样了……)

目前提供一个简单的解决方法,复制nvmd.exe并重命名为node.exe即可(在截图的这个目录下)

@EdenSpark
Copy link

刚重新安装遇到了同样的问题,设置版本后没有node命令
image

@1111mp
Copy link
Owner

1111mp commented Mar 13, 2024

你试试将%HOMEPATH%\.nvmd这个目录整个删除,然后再重新启动nvm-desktop客户端试试呢 看是否依旧会丢失node.exe文件

注意需要使用管理员权限运行

@Yfkj01
Copy link
Author

Yfkj01 commented Mar 14, 2024

这个目录下应该会有一个node.exe文件的,方便告知一下该文件不存在的原因吗(自己手动删除了或者更新新版本之后就这样了……)

目前提供一个简单的解决方法,复制nvmd.exe并重命名为node.exe即可(在截图的这个目录下)

删了,安装2遍都不行,用的管理员权限,复制nvmd.exe重命名为node.exe可以

@1111mp
Copy link
Owner

1111mp commented Mar 15, 2024

这就奇怪了 这些文件都是在启动的时候会复制写入到%HOMEPATH%\.nvmd\bin目录下的 这是相关的代码:

async function updateToSchemaVersionDefault(version: number) {
  if (version >= 1) return;

  if (platform === "win32") {
    // windows
    await setNvmdToPathForWindows();

    const exeSourceFile = app.isPackaged
      ? join(process.resourcesPath, "assets", "sources", `${arch}.exe`)
      : join(__dirname, "../../..", "assets", "sources", `${arch}.exe`);
    const cmdSourceFile = app.isPackaged
      ? join(process.resourcesPath, "assets", "sources", "temp.cmd")
      : join(__dirname, "../../..", "assets", "sources", "temp.cmd");

    const promises: Array<Promise<void>> = [];

    promises.push(copy(exeSourceFile, join(BIN_DIR, "nvmd.exe")).catch((_err) => {}));

    ["node", "npm", "npx", "corepack"].forEach((name) => {
      promises.push(copy(exeSourceFile, join(BIN_DIR, `${name}.exe`)).catch((_err) => {}));

      if (name !== "node") {
        promises.push(copy(cmdSourceFile, join(BIN_DIR, `${name}.cmd`)).catch((_err) => {}));
      }
    });

    await Promise.all(promises);

    setSchemaVersion(CURRENT_MIGRATION_VERSION);
    return;
  }

  // remove file: .nvmd/shell
  if (await pathExists(`${APPDIR}/shell`)) {
    await remove(`${APPDIR}/shell`);
  }

  // remove file: .nvmd/nvmd.sh
  if (await pathExists(`${APPDIR}/nvmd.sh`)) {
    await remove(`${APPDIR}/nvmd.sh`);
  }

  // macOS
  const targetFile = join(BIN_DIR, "nvmd");

  const sourceFile = app.isPackaged
    ? join(process.resourcesPath, "assets", "sources", "nvmd")
    : join(__dirname, "../../..", "assets", "sources", "nvmd");

  await copy(sourceFile, targetFile).catch((_err) => {});

  await Promise.all(
    ["node", "npm", "npx", "corepack"].map((name) =>
      symlink(targetFile, join(BIN_DIR, name)).catch((_err) => {})
    )
  );

  setSchemaVersion(CURRENT_MIGRATION_VERSION);
  return;
}

然后当后续版本升级时会替换掉所有的*.exe的文件:

async function updateToSchemaVersionLast(version: number) {
  if (version >= CURRENT_MIGRATION_VERSION) return;

  // Macos or Linux
  if (platform !== "win32") {
    const targetFile = join(BIN_DIR, "nvmd");

    await remove(targetFile);

    const sourceFile = app.isPackaged
      ? join(process.resourcesPath, "assets", "sources", "nvmd")
      : join(__dirname, "../../..", "assets", "sources", "nvmd");
    await copy(sourceFile, targetFile).catch((_err) => {});

    await setSchemaVersion(CURRENT_MIGRATION_VERSION);
    return;
  }

  // Windows
  const targetFile = join(BIN_DIR, "nvmd.exe");

  await remove(targetFile);

  const sourceFile = app.isPackaged
    ? join(process.resourcesPath, "assets", "sources", `${arch}.exe`)
    : join(__dirname, "../../..", "assets", "sources", `${arch}.exe`);
  await copy(sourceFile, targetFile).catch((_err) => {});

  async function updateFile(fileName: string) {
    const filePath = join(BIN_DIR, fileName);

    await remove(filePath);

    await copy(sourceFile, filePath).catch((_err) => {});

    return;
  }

  const files = await readdir(BIN_DIR);

  await Promise.all(
    files.filter((name) => name.endsWith(".exe")).map((fileName) => updateFile(fileName))
  );

  await setSchemaVersion(CURRENT_MIGRATION_VERSION);
  return;
}

根据你们的截图来看 是有一些成功了有一些失败了 目前没有什么头绪.....感觉还是跟系统的权限有一些关系.....

@1111mp
Copy link
Owner

1111mp commented Mar 15, 2024

@Yfkj01 @EdenSpark 你们方便安装一下这个版本运行吗:Release test_log 里面添加了一些日志的记录

  • 安装好之后先删除%HOMEPATH%\.nvmd目录下的bin\目录和migration文件,然后再启动。
  • 启动之后日志会记录在%HOMEPATH%\.nvmd\main.log文件中

然后麻烦提供一下这个日志文件,以用来定位具体的问题。谢谢 🌹

@lainbo
Copy link

lainbo commented Mar 29, 2024

出现了和这个问题反过来的问题。npm.exe不存在,但是node.exe存在

@1111mp
Copy link
Owner

1111mp commented Mar 29, 2024

@Yfkj01 @EdenSpark 你们方便安装一下这个版本运行吗:Release test_log 里面添加了一些日志的记录

  • 安装好之后先删除%HOMEPATH%\.nvmd目录下的bin\目录和migration文件,然后再启动。
  • 启动之后日志会记录在%HOMEPATH%\.nvmd\main.log文件中

然后麻烦提供一下这个日志文件,以用来定位具体的问题。谢谢 🌹

@lainbo 你可以试试安装 Release test_log 这个版本吗 然后安装说明提供一下log文件 以便定位到具体问题

Copy link

This issue is stale because it has been open for 30 days with no activity.

Copy link

This issue was closed because it has been inactive for 14 days since being marked as stale.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants