【问题标题】:ng server command opens file open option menung 服务器命令打开文件打开选项菜单
【发布时间】:2021-09-28 11:32:38
【问题描述】:

在 VS 代码编辑器中,ng serve 命令打开“你想如何打开这个文件?”对话框中

【问题讨论】:

  • 替代方案是 npm start 但我不明白为什么会这样。
  • 我终于找到了一个完整的解决方案。帖子已编辑。

标签: visual-studio-code angular11


【解决方案1】:

我在 Visual Studio Code 中执行 Docker 命令时遇到了类似的问题。我还有一个窗口询问“你想如何打开这个文件?”。我认为问题不在于 Visual Studio Code,而在于 Visual Studio Code 使用的 PowerShell。

我是这样解决的:

  • 运行 Get-Command -All docker | ForEach-对象路径
  • 在返回的文件路径中,删除不以 *.exe 结尾的路径(使用 删除项目):

对于 ng 应该是一样的。

致谢:https://stackoverflow.com/a/63981418/1816014

【讨论】:

  • 直到您的帖子的最后一行是答案,最后一行将所有内容更改为 NAA(不是答案),并被标记为这样。如果您想得到答案,请使用询问按钮。
  • 变通方法也是一种解决方案。在 Internet 上有很多地方可以找到这个问题,但无处解决,也没有提供解决方法。我认为有些人会为解决方法感到高兴。而且,对于这两个命令(node、Docker),命令行就足够了。
  • 我终于找到了一个完整的解决方案。
【解决方案2】:

Petr Freiberg 的回答帮助我找到了我认为更好的解决方案。我们应该更新我们的 PATH 变量,以便首先找到“正确”的命令,而不是删除对系统可能实际上很重要或可能不重要的文件。

在我的情况下,我的 npm 路径按以下顺序排列:

  1. C:\Users\Me\AppData\Roaming\npm\node_modules\@angular\cli\bin
  2. C:\Users\Me\AppData\Roaming\npm

我刚刚切换了顺序,以便 C:\Users\Me\AppData\Roaming\npm 排在第一位。

问题是终端正在寻找第一个“命令匹配”,它可能只是一个文件,这就是为什么它会询问您要在哪里打开它。

我确实按照 Petr 的建议运行了命令 Run Get-Command -All ng | ForEach-Object Path,这引发了我在此处描述的订单问题。

【讨论】:

    【解决方案3】:

    我遇到了同样的问题,在尝试运行 ng -v 或 ng --version 时,它会弹出一个打开选项编辑器,它会提供以下 ng.js 文本...

    #!/usr/bin/env node
    'use strict';
     
    // Provide a title to the process in `ps`.
    // Due to an obscure Mac bug, do not start this title with any symbol.
    try {
      process.title = 'ng ' + Array.from(process.argv).slice(2).join(' ');
    } catch (_) {
      // If an error happened above, use the most basic title.
      process.title = 'ng';
    }
     
    // This node version check ensures that extremely old versions of node are not used.
    // These may not support ES2015 features such as const/let/async/await/etc.
    // These would then crash with a hard to diagnose error message.
    // tslint:disable-next-line: no-var-keyword
    var version = process.versions.node.split('.').map((part) => Number(part));
    if (version[0] % 2 === 1 && version[0] > 14) {
      // Allow new odd numbered releases with a warning (currently v15+)
      console.warn(
        'Node.js version ' +
          process.version +
          ' detected.\n' +
          'Odd numbered Node.js versions will not enter LTS status and should not be used for production.' +
          ' For more information, please see https://nodejs.org/en/about/releases/.',
      );
     
      require('../lib/init');
    } else if (
      version[0] < 12 ||
      version[0] === 13 ||
      (version[0] === 12 && version[1] < 14) ||
      (version[0] === 14 && version[1] < 15)
    ) {
      // Error and exit if less than 12.14 or 13.x or less than 14.15
      console.error(
        'Node.js version ' +
          process.version +
          ' detected.\n' +
          'The Angular CLI requires a minimum Node.js version of either v12.14 or v14.15.\n\n' +
          'Please update your Node.js version or visit https://nodejs.org/ for additional instructions.\n',
      );
     
      process.exitCode = 3;
    } else {
      require('../lib/init');
    }
     
    what is the error here, i tried uninstall clear cache and install but still same error....
    

    【讨论】:

    • 请不要发布“我也是”作为答案。相反,您可以将此问题加注为收藏夹,以便收到任何新答案的通知。
    • 我想当我更新 angular 和 npm 版本时,它已经解决了。
    • npm update -g 不起作用
    猜你喜欢
    • 2018-12-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-25
    • 2019-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-12
    相关资源
    最近更新 更多