gpt4 book ai didi

Angular 12 aws-sdk 2.910.0 错误 : Module not found: Error: Can't resolve 'util' in '.\.\.\node_modules\aws-sdk\lib'

转载 作者:行者123 更新时间:2023-12-04 11:26:04 29 4
gpt4 key购买 nike

在从 Angular 11 移动到 12 之前,没有发生以下错误并且应用程序能够使用 aws-sdk库来访问我的 S3 存储桶:

./node_modules/aws-sdk/lib/event_listeners.js:572:21-44 - Error: Module not found: Error: Can't resolve 'util' in 'S:\Source\sttutter-ui\node_modules\aws-sdk\lib'
Did you mean './util'?
Requests that should resolve in the current directory need to start with './'.
Requests that start with a name are treated as module requests and resolve within module directories (S:/Source/sttutter-ui, node_modules).
If changing the source code is not an option there is also a resolve options called 'preferRelative' which tries to resolve these kind of requests in the current directory too.

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: { "util": require.resolve("util/") }'
- install 'util'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "util": false }

package.json
{
"name": "x",
"version": "0.0.0",
"license": "commercial",
"private": true,
"engines": {
"node": ">= 10.0.0"
},
"dependencies": {
"@angular/animations": "~12.0.1",
"@angular/common": "~12.0.1",
"@angular/compiler": "~12.0.1",
"@angular/core": "~12.0.1",
"@angular/forms": "~12.0.1",
"@angular/platform-browser": "~12.0.1",
"@angular/platform-browser-dynamic": "~12.0.1",
"@angular/router": "~12.0.1",
"@ng-bootstrap/ng-bootstrap": "^9.1.1",
"@ngrx/store": "^12.0.0",
"aws-sdk": "^2.910.0",
"ngrx-store-freeze": "^0.2.4",
"ngrx-store-logger": "^0.2.4",
"prando": "^6.0.1",
"rxjs": "~6.6.0",
"tslib": "^2.1.0",
"zone.js": "~0.11.4"
},
"devDependencies": {
"@angular-devkit/build-angular": "~12.0.1",
"@angular/cli": "~12.0.1",
"@angular/compiler-cli": "~12.0.1",
"@types/jasmine": "~3.6.0",
"@types/node": "^12.11.1",
"jasmine-core": "~3.7.0",
"karma": "~6.3.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.0.3",
"karma-jasmine": "~4.0.0",
"karma-jasmine-html-reporter": "^1.5.0",
"typescript": "~4.2.3"
},
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test"
}
}
我试过删除 node_modules目录和运行 npm install在网上搜索这个错误似乎表明这是一个 webpack问题...基于这些对话,我不知道如何让它再次工作。
我应该切换到 aws-sdk-js即使 aws-sdk一直工作到今天?
寻求有关如何解决此问题的建议
谢谢!

最佳答案

我也遇到了这个问题,不确定官方路径应该是什么,但下面的方法对我有用。

  • npm install -S util
  • 添加 (window as any).global.util = (window as any).global.util || require("util").util;给您的 polyfills.ts文件。
  • 关于Angular 12 aws-sdk 2.910.0 错误 : Module not found: Error: Can't resolve 'util' in '.\.\.\node_modules\aws-sdk\lib' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67627208/

    29 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com