所以我有一個有角度的專案,它出錯了,需要一些“polyfilling”。由于 Angular 不允許在不匯出的情況下編輯 webpack.config.js 檔案,我認為預期的意圖是讓開發人員編輯 polyfill.ts 檔案。現在 src 檔案夾中的 polyfill.ts 確實可以識別關鍵字“resolve”,因為它以這種方式從 dns 匯入:
import {resolve} from 'dns';
這是 Angular 的典型特征。但是來自 Angular 的錯誤訊息表明這個匯入的決議應該有方法 .fallback 而它沒有。
這是 polyfill.ts 代碼的影像:

這是前面提到的 Angular 錯誤的片段:

有誰知道 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.
uj5u.com熱心網友回復:
結合這篇文章:
用于 node.js crypto-js 的 webpack 5 angular polyfill
對于此錯誤,不需要 polyfill。只需編輯 angular.json 和 tsconfig.json 檔案。
非 polyfilling 錯誤源于沒有規范的服務器/客戶端設定。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/372546.html
