【问题标题】:Ng serve works in Windows but fails in UbuntuNg serve 在 Windows 中工作,但在 Ubuntu 中失败
【发布时间】:2018-09-16 06:02:25
【问题描述】:

我已经尝试并阅读了有关此问题的所有问题,但我无法解决它。 我的 Angular 4 程序在 Windows 中成功编译,但在 Ubuntu 中提供错误。并且 ng build --prob 在 Ubuntu 或 Windows 上不起作用。这是我在编译时遇到的错误的屏幕截图。任何人都可以帮忙吗?

【问题讨论】:

  • 你运行npm i命令了吗?
  • 我注意到你写了ng build --prob 。你试过ng build --prod
  • 请记住,Linux 中的文件路径是区分大小写的,因此如果该目录实际上称为payment 而不是Payment,例如,Linux 将找不到它。
  • 奇怪的是,在经历了几乎所有的努力和尝试之后,问题只是 Ubuntu 区分大小写而 Windows 不区分,我更正了所有目录和地址中的大写和小写它编译了!

标签: angular ubuntu compilation


【解决方案1】:

正如我所见,问题不在于编译,而在于查找提到和要获取的文件。

Ubuntu (Linux) 和 Windows 有不同的指令集和遍历文件的方式。

例如:在 Windows 中的 cmd 窗口 cd c: 可以工作,在 Ubuntu 中 c:/ 可以工作。

我的建议是在 Ubuntu 中创建新项目,并请理解如何获取文件,需要在单个文件中进行“URL”更正(尽管这是也很奇怪)。

您的项目在 Windows 中正常运行并且打开时没有错误(如果确实如此)——表明您的 Angular-Code、npm、angular-cli pakcage 或 NodeJs 没有任何问题。

只是为了预防起见——删除 Node、NPM 和 Angular-CLI 并将它们从 ubuntu 中删除,然后重新安装所有 3 个——NodeJS、NPM、Angular-CLI。有时,由于 Node 和 NPM 的版本不是最新的,会发生一些奇怪的错误。 (而且,您现在正在新计算机上编译您的项目——这意味着 Node/NPM/Angular-CLI 的版本可能与您之前的 Windows 计算机中的不同)。那么,为什么要冒险。只需从新系统中删除并重新安装这 3 个依赖项……然后 ping 回……会发生什么!

【讨论】:

    【解决方案2】:

    确保您在执行 ngServe 时位于项目所在的正确目录中。
    还要确保你已经用正确的路径注入了 app.module.ts 中的所有组件。

    【讨论】:

      【解决方案3】:
      Check if the imports are proper in the below listed files:
      app.module.ts
      payment.service.ts
      app-routing.module.ts
      
      Example:
      Say, i have a js file and two child directories under a root directory as mentioned below.
      
      server.js
      model/user.js
      routes/api/home.js
      routes/api/user.js
      
      If i need to import user.js in the "model directory" into server.js , i will use path: "./model/user"
      Note: Here the model directory is in the same directory as that of server.js
      
      If i need to import user.js in the "model directory" into routes/api/user.js, i will use path: "../../model/user"
      
      In your case, update the path based on where the files are stored. That should solve the problem.
      

      【讨论】:

        【解决方案4】:

        只需用 git 重命名 GIT 就可以了,Linux 区分大写和小写。

        【讨论】:

          猜你喜欢
          • 2022-07-15
          • 1970-01-01
          • 1970-01-01
          • 2018-06-10
          • 2022-01-26
          • 1970-01-01
          • 2021-04-13
          • 2010-10-08
          • 1970-01-01
          相关资源
          最近更新 更多