且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

更新到 Angular v6 - 找不到模块:错误:无法解析“fs"

更新时间:2022-06-12 09:32:53

2020 年更新

参见 Angular v9 的 答案.

See answer of Marc for Angular v9.

2019 年更新

查看评论,根据@Tahlil 现在是可能的.这适用于 Angular v8(常春藤编译器)请参阅此答案.它将特定模块设置为 false 以便在 package.json 中的浏览器中使用.

See comment, according @Tahlil it is now possible. This works for Angular v8 (Ivy compiler) see this answer. It sets specific modules to false for use in the browser in package.json.

原答案

好吧,几个小时后我得出结论,我收集到的答案是真正的答案:

Ok after hours I come to the conclusion with the answers I gathered that the real answer is:

你不能在 Angular v6 中使用 fs

You can't use fs anymore in Angular v6

此外,由于无法再弹出 webpack 配置,因此无法告诉 webpack 忽略 fs 要求

Furthermore, since it's not possible anymore to eject the webpack configuration, there is no way to tell webpack to ignore the fs require

关于这个主题有一个未解决的问题:https://github.com/angular/angular-cli/issues/10681

There is an open issue about this subject: https://github.com/angular/angular-cli/issues/10681

PS:我在服务器端使用 fs 加载翻译,我通过遵循@xuhcc 的解决方案解决了这个问题,参见 https://github.com/ngx-translate/core/issues/754

P.S.: I was using fs to load the translations on the server side, I overcome the problem by following solution of @xuhcc, see https://github.com/ngx-translate/core/issues/754