Angular5:TypeScript编译中缺少polyfills.ts和\ main.ts

Jal*_*lle 15 typescript webpack package.json angular-cli angular

这是我的Angular5项目结构.

在此输入图像描述

双方tsconfig.app.jsonpackage.json包含这部分

 "include": [
      "/src/main.ts",
      "/src/polyfills.ts"
    ]
Run Code Online (Sandbox Code Playgroud)

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

    \polyfills.ts & \main.ts is missing from the TypeScript compilation. 
Please make sure it is in your tsconfig via the 'files' or 'include' property.
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述 任何人都知道这里缺少什么?

  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"
  ]
}
Run Code Online (Sandbox Code Playgroud)

LFe*_*lix 11

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

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

  • Windows 10上具有目录连接(mklink/j)的相同问题! (4认同)
  • 编辑angular.json在节点“ projects / {yourprojectname} / architect / build / options”下添加以下属性应该会有所帮助:“ preserveSymlinks”:true (4认同)
  • 同样的问题在这里!感谢分享。 (2认同)

小智 6

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


use*_*994 -1

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

尝试更改:

"/src/main.ts",
Run Code Online (Sandbox Code Playgroud)

"src/main.ts",
Run Code Online (Sandbox Code Playgroud)

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