0

我在 Angular 13 上,我正在尝试使用反射元数据包,但我得到奇怪的模块未找到错误:无法解析 '*\node_modules\reflect-metadata' 中的 'Crypto'。我已经尝试了堆栈溢出中列出的所有解决方案,但它对我不起作用。

我得到的实际错误 ./node_modules/reflect-metadata/Reflect.js:840:35-52 - 错误:找不到模块:错误:无法解析 'C:\Users\monke\Documents\Epicon\ 中的 'crypto' esb-ui\node_modules\reflect-元数据'

重大变化:webpack < 5 用于默认包含 node.js 核心模块的 polyfill。这已不再是这种情况。验证你是否需要这个模块并为它配置一个 polyfill。

如果你想包含一个 polyfill,你需要: - 添加一个后备 'resolve.fallback: { "crypto": require.resolve("crypto-browserify") }' - 安装 'crypto-browserify' 如果你不想要包含一个 polyfill,你可以使用这样的空模块:resolve.fallback: { "crypto": false }

这是我的包 JSON 依赖项。

    "@angular/animations": "^13.0.2",
    "@angular/common": "^13.0.2",
    "@angular/compiler": "^13.0.2",
    "@angular/core": "^13.0.2",
    "@angular/forms": "^13.0.2",
    "@angular/platform-browser": "^13.0.2",
    "@angular/platform-browser-dynamic": "^13.0.2",
    "@angular/platform-server": "^13.0.2",
    "@angular/router": "^13.0.2",
    "@angular/upgrade": "13.0.2",
    "@asymmetrik/leaflet-d3": "^4.4.0",
    "@asymmetrik/ngx-leaflet": "^6.0.1",
    "@fortawesome/fontawesome-free": "^5.13.0",
    "angular-gridster2": "^12.0.0",
    "angular2-uuid": "1.1.1",
    "backoff-rxjs": "^6.5.7",
    "bootstrap": "^4.4.1",
    "c3": "^0.7.15",
    "case": "^1.6.2",
    "chart.js": "^3.6.0",
    "chartjs-adapter-moment": "^1.0.0",
    "classlist.js": "1.1.20150312",
    "core-js": "3.2.1",
    "d3": "~5.9.4",
    "d3-hexbin": "0.2.2",
    "dropzone": "5.2.0",
    "html2canvas": "1.0.0-alpha.12",
    "http-server": "^0.12.1",
    "immutable": "3.8.2",
    "is-in-viewport": "^3.0.4",
    "jquery": "3.2.1",
    "jquery-base64": "1.0.0",
    "jquery-ui": "1.12.1",
    "jquery-ui-monthpicker": "^1.0.3",
    "jquery-xml2json": "0.0.8",
    "jsplumbtoolkit": "file:./thirdparty_modules/jsplumbtoolkit-1.18.5.tgz",
    "jsplumbtoolkit-angular": "file:./thirdparty_modules/jsplumbtoolkit-angular-1.18.5.tgz",
    "karma-edge-launcher": "0.4.2",
    "karma-ie-launcher": "1.0.0",
    "leaflet": "^1.6.0",
    "md5": "^2.2.1",
    "moment": "^2.24.0",
    "monaco-editor": "^0.30.1",
    "monaco-languageclient": "^0.13.0",
    "ngx-bootstrap": "^5.5.0",
    "ngx-monaco-editor": "^12.0.0",
    "popper.js": "^1.16.1",
    "postinstall": "^0.4.2",
    "reflect-metadata": "0.1.3",
    "rxjs": "^6.5.4",
    "time-ago-pipe": "^1.3.2",
    "tinycolorpicker": "0.9.5",
    "tslib": "^2.0.0",
    "underscore": "1.8.3",
    "vkbeautify": "0.99.3",
    "zone.js": "~0.11.4"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~13.0.3",
    "@angular-devkit/core": "13.0.3",
    "@angular-eslint/builder": "1.2.0",
    "@angular-eslint/eslint-plugin": "1.2.0",
    "@angular-eslint/eslint-plugin-template": "1.2.0",
    "@angular-eslint/template-parser": "1.2.0",
    "@angular/cli": "^13.0.3",
    "@angular/compiler-cli": "^13.0.2",
    "@cypress/schematic": "^1.6.0",
    "@types/c3": "^0.7.4",
    "@types/d3-hexbin": "0.2.1",
    "@types/jasmine": "~3.6.0",
    "@types/jasmine-jquery": "^1.5.33",
    "@types/jasminewd2": "^2.0.8",
    "@types/jquery": "^3.3.33",
    "@types/jqueryui": "1.12.4",
    "@types/jsonpath": "0.2.0",
    "@types/leaflet": "1.2.6",
    "@types/node": "^12.11.1",
    "@types/underscore": "1.8.8",
    "@typescript-eslint/eslint-plugin": "4.3.0",
    "@typescript-eslint/parser": "4.3.0",
    "codelyzer": "^6.0.0",
    "current-git-branch": "^1.1.0",
    "cypress": "latest",
    "cypress-file-upload": "^5.0.8",
    "cypress-xpath": "^1.6.2",
    "del-cli": "^1.1.0",
    "eslint": "^7.6.0",
    "eslint-config-prettier": "^8.3.0",
    "eslint-plugin-prettier": "^4.0.0",
    "eslint-plugin-sort-class-members": "^1.11.0",
    "eslint-plugin-unused-imports": "^1.1.4",
    "fs-extra": "^8.1.0",
    "git-describe": "^4.0.4",
    "husky": "^4.2.5",
    "jasmine-core": "~3.6.0",
    "jasmine-jquery-matchers": "^2.1.0",
    "jasmine-reporters": "^2.3.2",
    "jasmine-spec-reporter": "~5.0.0",
    "jasmine-test-container-support": "^0.1.2",
    "jsonpath": "1.0.0",
    "karma": "~6.3.9",
    "karma-chrome-launcher": "~3.1.0",
    "karma-cli": "1.0.1",
    "karma-coverage-istanbul-reporter": "~3.0.2",
    "karma-firefox-launcher": "1.1.0",
    "karma-jasmine": "~4.0.0",
    "karma-jasmine-html-reporter": "^1.5.0",
    "karma-jasmine-jquery": "^0.1.1",
    "karma-parallel": "^0.3.1",
    "karma-safari-launcher": "1.0.0",
    "karma-sonarqube-unit-reporter": "0.0.18",
    "karma-teamcity-reporter": "^1.1.0",
    "less": "^3.11.1",
    "lint-staged": "^8.2.1",
    "ng-lint-staged": "7.0.2",
    "prettier": "^1.19.1",
    "pretty-quick": "^3.1.1",
    "protractor": "~7.0.0",
    "protractor-http-client": "^1.0.4",
    "protractor-jasmine2-screenshot-reporter": "^0.5.0",
    "ts-node": "~7.0.0",
    "typescript": "~4.4.4",
    "typescript-require": "^0.3.0"
  }```
4

1 回答 1

0

您可以将以下内容添加到 tsconfig.json 以解决加密警告:

"paths": {
      "crypto": [
        "node_modules/crypto-js"
      ]
    },

并将以下添加到您的 angular.json 文件中:

"options": {
"allowedCommonJsDependencies": [
              "crypto-js"
            ],
...
}
于 2022-01-11T03:08:32.737 回答