【问题标题】:Vite running as npm run dev but not directly in terminalVite 以 npm run dev 运行但不直接在终端中运行
【发布时间】:2023-02-16 20:22:07
【问题描述】:

我的项目面临这个奇怪的问题。这是我遵循的步骤

  1. npm create vite@latest
  2. cd 到项目文件夹。
  3. npm i
  4. npm run dev

    这很好用,但是没有生成 vite.config.js 文件。我尝试运行vite,但随后出现此错误。

    vite: The term 'vite' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

    此外,使用 npm run dev --host 也不能使其在 LAN 上可用。适用于实时服务器。

    我正在使用最新的 npm。

【问题讨论】:

    标签: npm terminal vite


    【解决方案1】:

    我遇到了类似的问题。

    • npm run dev|build|preview 从 shell 工作。

    • vite build --mode other 在 shell 中不起作用。

    • npm exec vite -- build --mode other 从 shell 工作。

    我想要一个使用不同于 .env.development 或 .env.production 的 .env.other 的构建。

    所以运行:

    • npm exec vite -- build --mode other
    • npm run preview

    在站点服务器设置为“其他”模式的情况下正确启动 VITE,并正确使用“.env.other”ENV 设置。

    我不知道为什么在 MacOS 上,我看到 VITE 没有被 npm 正确安装为 bin。我做了所有的技巧(删除 node_modules,重新安装等)

    【讨论】:

      猜你喜欢
      • 2023-01-02
      • 2021-12-24
      • 2022-12-20
      • 2020-02-18
      • 2022-08-06
      • 2018-12-12
      • 1970-01-01
      • 1970-01-01
      • 2020-06-10
      相关资源
      最近更新 更多