我该如何解决“错误:TypeScript编译中缺少\ src \ main.ts。”

时间:2020-10-29 15:46:46

标签: javascript node.js angular typescript webpack

我在StackOverFlow上尝试了所有可能的解决方案,并且还卸载了node和angular两者。 3天内3次。 我不知道为什么会这样。 这是在“ ng-serve”上发生的


C:\...\my-app>ng serve
Your global Angular CLI version (10.2.0) is greater than your local
version (10.1.4). The local Angular CLI version is used.

To disable this warning use "ng config -g cli.warnings.versionMismatch false".

chunk {main} main.js, main.js.map (main) 2.78 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 1.61 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.15 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 1.56 kB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 342 kB [initial] [rendered]
Date: 2020-10-29T15:32:18.382Z - Hash: 73a81c6903f44c830485 - Time: 5411ms

ERROR in C:\...\my-app/src/main.ts
Module build failed (from C:\...\my-app/node_modules/@ngtools/webpack/src/index.js):
Error: C:\...\my-app\src\main.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
    at AngularCompilerPlugin.getCompiledFile (C:\...\my-app\node_modules\@ngtools\webpack\src\angular_compiler_plugin.js:949:23)
    at C:\...\my-app\node_modules\@ngtools\webpack\src\loader.js:43:31
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

ERROR in C:\...\my-app/src/polyfills.ts
Module build failed (from C:\...\my-app/node_modules/@ngtools/webpack/src/index.js):
Error: C:\...\my-app\src\polyfills.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
    at AngularCompilerPlugin.getCompiledFile (C:\...\my-app\node_modules\@ngtools\webpack\src\angular_compiler_plugin.js:949:23)
    at C:\...\my-app\node_modules\@ngtools\webpack\src\loader.js:43:31
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **

有什么想法吗? 谢谢

2 个答案:

答案 0 :(得分:0)

尝试以下步骤:

  1. 像您的角度CLI一样升级到角度10.2.0
  2. 更新所有依赖项npm oudated,然后更新npm update 必填。
  3. 删除dist文件夹和node_modules文件,并依次使用npm installng serve

答案 1 :(得分:0)

您是否有机会为源代码使用符号链接位置并从链接位置编译? 如果是这样你应该添加

"preserveSymlinks": true,

projects/[您的项目名称]/architect/build/options下的angular.json