【发布时间】:2021-12-01 11:55:46
【问题描述】:
所以我有一个 Angular 项目出错了,需要一些“polyfilling”。由于 Angular 不允许在不导出 webpack.config.js 文件的情况下对其进行编辑,我认为预期的意图是让开发人员编辑 polyfill.ts 文件。现在 src 文件夹中的 polyfill.ts 确实可以识别关键字“resolve”,因为它是以这种方式从 dns 导入的:
import {resolve} from 'dns';
这对于 Angular 来说很典型。但是来自 Angular 的错误消息表明,这个导入的解析应该有它没有的方法 .fallback。
有谁知道 Angular 期望这段代码放在哪里?除了我在这篇文章中的假设之外,polyfill.ts 文件是否还有其他用途?实际处理 polyfill 是否需要更健壮的代码?我假设它会全部放在这里,否则为什么将文件放在名为 polyfill 的 src 文件夹中,整个项目都可以看到它?如果这个问题看起来太宽泛,请道歉,因为我在黑暗中装模作样,任何和所有批评/建议都会受到赞赏。
以下是 Angular 生成的完整错误:
$ ng serve
Your global Angular CLI version (13.0.1) is greater than your local version (12.2.13). The local Angular CLI version is used.
To disable this warning use "ng config -g cli.warnings.versionMismatch false".
- Generating browser application bundles (phase: setup)...
√ Browser application bundle generation complete.
Initial Chunk Files | Names | Size
vendor.js | vendor | 6.48 MB
polyfills.js | polyfills | 510.73 kB
styles.css, styles.js | styles | 383.69 kB
main.js | main | 81.66 kB
runtime.js | runtime | 6.69 kB
| Initial Total | 7.44 MB
Build at: 2021-11-26T16:15:03.838Z - Hash: b77d276f8b953e0e2990 - Time: 10837ms
./node_modules/sequelize/lib/dialects/abstract/connection-manager.js:82:15-63 - Warning: Critical dependency: the request of a dependency is an expression
./node_modules/sequelize/lib/dialects/abstract/connection-manager.js:89:13-32 - Warning: Critical dependency: the request of a dependency is an expression
./node_modules/sequelize/lib/dialects/mssql/query-generator.js:8:20-49 - Error: Module not found: Error: Can't resolve 'crypto' in 'C:\again\software-engineering-team-project-fourtothefloor\node_modules\sequelize\lib\dialects\mssql'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "crypto": require.resolve("crypto-browserify") }'
- install 'crypto-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "crypto": false }
./node_modules/sequelize/lib/dialects/postgres/hstore.js:3:15-35 - Error: Module not found: Error: Can't resolve 'pg-hstore' in 'C:\again\software-engineering-team-project-fourtothefloor\node_modules\sequelize\lib\dialects\postgres'
./node_modules/sequelize/lib/dialects/sqlite/connection-manager.js:5:11-24 - Error: Module not found: Error: Can't resolve 'fs' in 'C:\again\software-engineering-team-project-fourtothefloor\node_modules\sequelize\lib\dialects\sqlite'
./node_modules/sequelize/lib/model.js:5:15-32 - Error: Module not found: Error: Can't resolve 'assert' in 'C:\again\software-engineering-team-project-fourtothefloor\node_modules\sequelize\lib'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "assert": require.resolve("assert/") }'
- install 'assert'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "assert": false }
** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
× Failed to compile.
【问题讨论】:
标签: node.js angular typescript webpack polyfills