【问题标题】:Angular5 :polyfills.ts & \main.ts is missing from the TypeScript compilationTypeScript 编译中缺少 Angular5 :polyfills.ts & \main.ts
【发布时间】:2018-08-12 00:23:03
【问题描述】:

这是我的 Angular5 项目结构。

tsconfig.app.jsonpackage.json 都包含此部分

 "include": [
      "/src/main.ts",
      "/src/polyfills.ts"
    ]

但无论我尝试什么,我仍然会收到此错误:

    \polyfills.ts & \main.ts is missing from the TypeScript compilation. 
Please make sure it is in your tsconfig via the 'files' or 'include' property.

有人知道这里缺少什么吗?

  tsconfig.json
        {
          "compileOnSave": false,
          "compilerOptions": {
            "outDir": "./dist/out-tsc",
            "sourceMap": true,
            "declaration": false,
            "moduleResolution": "node",
            "emitDecoratorMetadata": true,
            "experimentalDecorators": true,
            "target": "es5",
            "typeRoots": [
              "node_modules/@types"
            ],
            "lib": [
              "es2017",
              "dom"
            ]
          }
        }
src/tsconfig.app.json
{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/app",
    "baseUrl": "./",
    "module": "es2015",
    "types": []
  },
  "include": [
    "main.ts",
    "polyfills.ts"
  ],
  "exclude": [
    "test.ts",
    "**/*.spec.ts"
  ]
}

【问题讨论】:

  • 如果有 src\tsconfig.app.json 和 tsconfig.json 文件,请提供完整的上下文
  • 帖子已更新......
  • 对我来说似乎还可以。什么是打字稿版本?并尝试 ./main.ts 路径。另一种可能性 - 尝试“文件”而不是“包含”
  • 并尝试更新 angular cli
  • 我遇到了同样的错误,但是如果我使用 --aot 标志运行本地环境,那么这个问题似乎会以某种方式得到解决。我仍然想对此进行一些解释

标签: angular typescript webpack angular-cli package.json


【解决方案1】:

这可能是因为您使用的是绝对路径。

尝试更改:

"/src/main.ts",

"src/main.ts",

(或者可能只是"main.ts"

【讨论】:

    【解决方案2】:

    找到了解决办法。问题是因为我在符号链接目录中($HOME/dev -> d:\dev\ ) 移动到原始目录(d:\dev)并运行你的命令,它就可以工作了。

    来源:https://github.com/angular/angular-cli/issues/9909

    【讨论】:

    • 在具有目录连接 (mklink /j) 的 Windows 10 上存在相同问题!
    • 编辑 angular.json 以在节点“projects/{yourprojectname}/architect/build/options”下添加以下属性应该有帮助:“preserveSymlinks”:true
    • 关上前门
    • 同样的问题!感谢分享。
    【解决方案3】:

    我也有一段时间遇到过这个问题,我只是通过改变我的项目的位置来解决它。我把它放在系统以外的磁盘上(例如:d:, e: ...)

    【讨论】:

      【解决方案4】:

      编辑 angular.json 以在节点 projects/project/architect/build/options 下添加以下属性应该有助于使 "preserveSymlinks": true 工作。

      【讨论】:

      • 由于我(以前工作的 Angular)没有构建几个小时,这使得问题消失了......但这到底是做什么的呢?我没有将源代码移动到其他文件夹或其他任何东西......
      • 对于 Angular 12 中的我来说,这是正确的答案。
      【解决方案5】:

      今天尝试在 Windows 10 上使用 Git Bash 构建 Angular 9 应用时遇到了这个问题。

      原来文件路径太长/嵌套 Git Bash 无法处理!或者 Git Bash 在某些地方使用了符号链接。

      改为从 Cmd / PowerShell 运行 ng build,它运行良好。

      【讨论】:

        猜你喜欢
        • 2021-02-03
        • 2018-10-01
        • 2021-02-12
        • 2019-01-05
        • 1970-01-01
        • 2020-11-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多