错误:模块构建失败(来自 ./node_modules/@ngtools/webpack/src/ivy/index.js):错误:发出

rak*_*258 21 angularjs angular

构建于:2022-09-14T11:34:20.503Z - 哈希:c51f599b4586fb6d - 时间:7780ms

\n

./src/main.ts - 错误:模块构建失败(来自 ./node_modules/@ngtools/webpack/src/ivy/index.js):\n错误:发出

\n

./src/polyfills.ts - 错误:模块构建失败(来自 ./node_modules/@ngtools/webpack/src/ivy/index.js):\n错误:发出

\n

错误:无法初始化 Angular 编译 - 无法读取 null 的属性(读取“fileName”)

\n

** Angular Live Development Server 正在监听 localhost:4200,打开浏览器 http://localhost:4200/ **

\n

\xc3\x97 编译失败。

\n

chu*_*its 6

这似乎是 Typescript 版本 >4.9.0 的问题。我还没有弄清楚那是什么,但一个可能的解决方法是,如果可以的话,将您的版本修改为 4.8.2,因为这个版本似乎没有这个问题。

如果我找到到底是什么导致了这个问题,我会再次发布。

  • 是的,我确认是 Typescript 的版本引发了这个错误,当我安装 EsLint 时,Typescript 会自动从 4.7.4 更新到 4.9.3,但如果我使用你的版本(4.8.2),我有相同的版本错误 ... (2认同)

小智 6

检查这个,可能会有所帮助, 这背后的基本原因可能是......对某些模块的递归调用。

例如

@NgModule({
     declarations: [],
     imports: [
        CommonModule,
        MatSliderModule,
        MaterialModule
     ],
     exports:[MatSliderModule]
    })
    export class MaterialModule { }
Run Code Online (Sandbox Code Playgroud)

在这里,Same MaterialModule正在导入 self。它增加了调用堆栈并导致上述错误。

这是一个条件。可能还有其他条件。


小智 3

尝试找到node_modules/@angular/compiler-cli/ngcc/ngcc_lock_file 文件并将其删除。或者只需删除您的node_modules文件夹并执行npm install