【问题标题】:AngularFireFunctionsModule from AngularFire Causes build errors来自 AngularFire 的 AngularFireFunctionsModule 导致构建错误
【发布时间】:2020-04-06 03:27:59
【问题描述】:

我在添加AngularFireFunctionsModule 时遇到了一些问题。出于某种原因,尽管已成功包含 AngularFireModuleAngularFirestoreModuleAngularFireAuthModule,但当我添加任何 AngularFireFunctions 时,我会遇到构建失败。

查看错误和警告,我唯一能理解的是它试图从错误的 node_modules 目录中查找依赖项。我不知道为什么会这样做。

以下是构建时的错误消息示例:

WARNING in ./firebase/functions/node_modules/firebase-functions/lib/config.js 55:23-36
Critical dependency: the request of a dependency is an expression

WARNING in ./firebase/functions/node_modules/firebase-functions/lib/config.js 78:23-36
Critical dependency: the request of a dependency is an expression

WARNING in ./firebase/functions/node_modules/grpc/src/grpc_extension.js 32:12-33
Critical dependency: the request of a dependency is an expression

WARNING in ./firebase/functions/node_modules/grpc/node_modules/node-pre-gyp/lib/pre-binding.js 20:22-48
Critical dependency: the request of a dependency is an expression

WARNING in ./firebase/functions/node_modules/grpc/node_modules/node-pre-gyp/lib/util/versioning.js 17:20-67
Critical dependency: the request of a dependency is an expression

WARNING in ./firebase/functions/node_modules/hash-stream-validation/index.js
Module not found: Error: Can't resolve 'fast-crc32c' in '/Users/name/pwa/firebase/functions/node_modules/hash-stream-validation'

WARNING in ./firebase/functions/node_modules/grpc/node_modules/minimatch/minimatch.js
Module not found: Error: Can't resolve 'path' in '/Users/name/pwa/firebase/functions/node_modules/grpc/node_modules/minimatch'

WARNING in ./firebase/functions/node_modules/write-file-atomic/index.js
Module not found: Error: Can't resolve 'worker_threads' in '/Users/name/pwa/firebase/functions/node_modules/write-file-atomic'

ERROR in ./firebase/functions/node_modules/@google-cloud/firestore/build/src/v1beta1/firestore_client.js
Module not found: Error: Can't resolve './firestore_client_config' in '/Users/name/pwa/firebase/functions/node_modules/@google-cloud/firestore/build/src/v1beta1'
ERROR in ./firebase/functions/node_modules/google-gax/build/src/operationsClient.js
Module not found: Error: Can't resolve './operations_client_config' in '/Users/name/pwa/firebase/functions/node_modules/google-gax/build/src'
ERROR in ./firebase/functions/node_modules/mime/index.js
Module not found: Error: Can't resolve './types/other' in '/Users/name/pwa/firebase/functions/node_modules/mime'
ERROR in ./firebase/functions/node_modules/mime/index.js
Module not found: Error: Can't resolve './types/standard' in '/Users/name/pwa/firebase/functions/node_modules/mime'
ERROR in ./firebase/functions/node_modules/@google-cloud/bigquery/node_modules/google-auth-library/build/src/auth/googleauth.js
Module not found: Error: Can't resolve 'child_process' in '/Users/name/pwa/firebase/functions/node_modules/@google-cloud/bigquery/node_modules/google-auth-library/build/src/auth'
ERROR in ./firebase/functions/node_modules/firebase-admin/node_modules/google-auth-library/build/src/auth/googleauth.js
Module not found: Error: Can't resolve 'child_process' in '/Users/name/pwa/firebase/functions/node_modules/firebase-admin/node_modules/google-auth-library/build/src/auth'
ERROR in ./firebase/functions/node_modules/google-auth-library/build/src/auth/googleauth.js
Module not found: Error: Can't resolve 'child_process' in '/Users/name/pwa/firebase/functions/node_modules/google-auth-library/build/src/auth'
ERROR in ./firebase/functions/node_modules/google-gax/node_modules/google-auth-library/build/src/auth/googleauth.js
Module not found: Error: Can't resolve 'child_process' in '/Users/name/pwa/firebase/functions/node_modules/google-gax/node_modules/google-auth-library/build/src/auth'
ERROR in ./firebase/functions/node_modules/grpc/node_modules/detect-libc/lib/detect-libc.js
Module not found: Error: Can't resolve 'child_process' in '/Users/name/pwa/firebase/functions/node_modules/grpc/node_modules/detect-libc/lib'
ERROR in ./firebase/functions/node_modules/graceful-fs/polyfills.js
Module not found: Error: Can't resolve 'constants' in '/Users/name/pwa/firebase/functions/node_modules/graceful-fs'
ERROR in ./firebase/functions/node_modules/@google-cloud/bigquery/node_modules/google-auth-library/build/src/crypto/node/crypto.js
Module not found: Error: Can't resolve 'crypto' in '/Users/name/pwa/firebase/functions/node_modules/@google-cloud/bigquery/node_modules/google-auth-library/build/src/crypto/node'
ERROR in ./firebase/functions/node_modules/@google-cloud/storage/src/file.js
Module not found: Error: Can't resolve 'crypto' in '/Users/name/pwa/firebase/functions/node_modules/@google-cloud/storage/src'
ERROR in ./firebase/functions/node_modules/aws-sign2/index.js
Module not found: Error: Can't resolve 'crypto' in '/Users/name/pwa/firebase/functions/node_modules/aws-sign2'
ERROR in ./firebase/functions/node_modules/aws4/aws4.js
Module not found: Error: Can't resolve 'crypto' in '/Users/name/pwa/firebase/functions/node_modules/aws4'
ERROR in ./firebase/functions/node_modules/crypto-random-string/index.js
Module not found: Error: Can't resolve 'crypto' in '/Users/name/pwa/firebase/functions/node_modules/crypto-random-string'
ERROR in ./firebase/functions/node_modules/ecc-jsbn/index.js
Module not found: Error: Can't resolve 'crypto' in '/Users/name/pwa/firebase/functions/node_modules/ecc-jsbn'
ERROR in ./firebase/functions/node_modules/firebase-admin/lib/auth/token-generator.js
Module not found: Error: Can't resolve 'crypto' in '/Users/name/pwa/firebase/functions/node_modules/firebase-admin/lib/auth'
ERROR in ./firebase/functions/node_modules/firebase-admin/node_modules/@google-cloud/storage/build/src/file.js
Module not found: Error: Can't resolve 'crypto' in '/Users/name/pwa/firebase/functions/node_modules/firebase-admin/node_modules/@google-cloud/storage/build/src'
ERROR in ./firebase/functions/node_modules/firebase-admin/node_modules/gcs-resumable-upload/build/src/index.js
Module not found: Error: Can't resolve 'crypto' in '/Users/name/pwa/firebase/functions/node_modules/firebase-admin/node_modules/gcs-resumable-upload/build/src'
ERROR in ./firebase/functions/node_modules/firebase-admin/node_modules/google-auth-library/build/src/crypto/node/crypto.js
Module not found: Error: Can't resolve 'crypto' in '/Users/name/pwa/firebase/functions/node_modules/firebase-admin/node_modules/google-auth-library/build/src/crypto/node'
ERROR in ./firebase/functions/node_modules/gcs-resumable-upload/build/src/index.js
Module not found: Error: Can't resolve 'crypto' in '/Users/name/pwa/firebase/functions/node_modules/gcs-resumable-upload/build/src'
ERROR in ./firebase/functions/node_modules/google-auth-library/build/src/pemverifier.js
Module not found: Error: Can't resolve 'crypto' in '/Users/name/pwa/firebase/functions/node_modules/google-auth-library/build/src'
ERROR in ./firebase/functions/node_modules/google-auth-library/build/src/auth/googleauth.js
Module not found: Error: Can't resolve 'crypto' in '/Users/name/pwa/firebase/functions/node_modules/google-auth-library/build/src/auth'
ERROR in ./firebase/functions/node_modules/google-auth-library/build/src/auth/oauth2client.js
Module not found: Error: Can't resolve 'crypto' in '/Users/name/pwa/firebase/functions/node_modules/google-auth-library/build/src/auth'
ERROR in ./firebase/functions/node_modules/google-auto-auth/index.js
Module not found: Error: Can't resolve 'crypto' in '/Users/name/pwa/firebase/functions/node_modules/google-auto-auth'
ERROR in ./firebase/functions/node_modules/google-gax/node_modules/google-auth-library/build/src/crypto/node/crypto.js
Module not found: Error: Can't resolve 'crypto' in '/Users/name/pwa/firebase/functions/node_modules/google-gax/node_modules/google-auth-library/build/src/crypto/node'
ERROR in ./firebase/functions/node_modules/hash-stream-validation/index.js
Module not found: Error: Can't resolve 'crypto' in '/Users/name/pwa/firebase/functions/node_modules/hash-stream-validation'
ERROR in ./firebase/functions/node_modules/http-signature/lib/verify.js
Module not found: Error: Can't resolve 'crypto' in '/Users/name/pwa/firebase/functions/node_modules/http-signature/lib'
ERROR in ./firebase/functions/node_modules/http-signature/lib/signer.js
Module not found: Error: Can't resolve 'crypto' in '/Users/name/pwa/firebase/functions/node_modules/http-signature/lib'
ERROR in ./firebase/functions/node_modules/jwa/index.js
Module not found: Error: Can't resolve 'crypto' in '/Users/name/pwa/firebase/functions/node_modules/jwa'
ERROR in ./firebase/functions/node_modules/oauth-sign/index.js
Module not found: Error: Can't resolve 'crypto' in '/Users/name/pwa/firebase/functions/node_modules/oauth-sign'
ERROR in ./firebase/functions/node_modules/request/lib/oauth.js
Module not found: Error: Can't resolve 'crypto' in '/Users/name/pwa/firebase/functions/node_modules/request/lib'
ERROR in ./firebase/functions/node_modules/request/lib/helpers.js
Module not found: Error: Can't resolve 'crypto' in '/Users/name/pwa/firebase/functions/node_modules/request/lib'
ERROR in ./firebase/functions/node_modules/request/lib/hawk.js
Module not found: Error: Can't resolve 'crypto' in '/Users/name/pwa/firebase/functions/node_modules/request/lib'
ERROR in ./firebase/functions/node_modules/sshpk/lib/certificate.js
Module not found: Error: Can't resolve 'crypto' in '/Users/name/pwa/firebase/functions/node_modules/sshpk/lib'
ERROR in ./firebase/functions/node_modules/sshpk/lib/fingerprint.js
Module not found: Error: Can't resolve 'crypto' in '/Users/name/pwa/firebase/functions/node_modules/sshpk/lib'
ERROR in ./firebase/functions/node_modules/sshpk/lib/signature.js
Module not found: Error: Can't resolve 'crypto' in '/Users/name/pwa/firebase/functions/node_modules/sshpk/lib'
ERROR in ./firebase/functions/node_modules/sshpk/lib/private-key.js
Module not found: Error: Can't resolve 'crypto' in '/Users/name/pwa/firebase/functions/node_modules/sshpk/lib'
ERROR in ./firebase/functions/node_modules/sshpk/lib/identity.js
Module not found: Error: Can't resolve 'crypto' in '/Users/name/pwa/firebase/functions/node_modules/sshpk/lib'
ERROR in ./firebase/functions/node_modules/sshpk/lib/key.js
Module not found: Error: Can't resolve 'crypto' in '/Users/name/pwa/firebase/functions/node_modules/sshpk/lib'

/Users/name/pwa/firebase/functions/node_modules/ 目录确实存在,但它不是使用 /Users/name/pwa/node_modules/ 进行节点依赖的 Angular 应用程序的一部分。

目录结构:

pwa
|-> firebase
||-> functions
|||-> distFirebase
|||-> node_modules (cloud functions)
|||-> src
||-> package.json
|-> node_modules (library root)
|-> src
||-> app
|||-> components
|||-> services
|-> package.json

我项目的 package.json 依赖项:

"dependencies": {
    "@angular/animations": "^8.2.14",
    "@angular/common": "^8.2.14",
    "@angular/compiler": "^8.2.14",
    "@angular/core": "^8.2.14",
    "@angular/fire": "^5.2.3",
    "@angular/forms": "^8.2.14",
    "@angular/http": "^7.2.15",
    "@angular/platform-browser": "^8.2.14",
    "@angular/platform-browser-dynamic": "^8.2.14",
    "@angular/pwa": "^0.12.4",
    "@angular/router": "^8.2.14",
    "@angular/service-worker": "^8.2.14",
    "@ngrx/effects": "^8.2.0",
    "@ngrx/store": "^8.2.0",
    "@ngrx/store-devtools": "^8.2.0",
    "@types/json-schema": "^7.0.3",
    "@types/stripe": "^6.32.13",
    "@types/stripe-checkout": "^1.0.3",
    "@types/stripe-v3": "^3.1.9",
    "core-js": "^2.6.10",
    "exif-js": "^2.3.0",
    "firebase": "^5.11.1",
    "rxjs": "^6.5.3",
    "ts-md5": "^1.2.7",
    "tslib": "^1.10.0",
    "zone.js": "~0.9.1"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.803.19",
    "@angular/cli": "^8.3.19",
    "@angular/compiler-cli": "^8.2.14",
    "@angular/language-service": "^8.2.14",
    "@types/google-libphonenumber": "^7.4.17",
    "@types/jasmine": "^2.8.16",
    "@types/jasminewd2": "^2.0.8",
    "@types/node": "~8.9.4",
    "codelyzer": "~4.2.1",
    "electron": "^2.0.18",
    "git-describe": "^4.0.4",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~1.7.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "^2.0.6",
    "karma-jasmine": "~1.1.1",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.3.0",
    "rxjs-tslint-rules": "^4.26.3",
    "ts-node": "~5.0.1",
    "tslint": "~5.9.1",
    "typescript": "~3.5.3"
  }

还有我的 App.Module

imports: [
    CommonModule,
    AppNavigationModule,
    AngularFireModule.initializeApp(environment.firebaseConfig),
    AngularFireAuthModule,
    AngularFirestoreModule,
    AngularFireFunctionsModule, // <-- Errors when added / Builds when removed
    FormsModule,
    ReactiveFormsModule,
  ],

有没有人遇到过类似的问题?问题是如何解决的?

谢谢。

【问题讨论】:

    标签: angular typescript angularfire2 package.json


    【解决方案1】:

    AngularFireFunctions 在内部导入 'firebase/functions'。您的目录结构使得 typescript 编译器将 'firebase/functions' 解析为 'pwa/firebase/functions',这会在构建期间导致错误消息。在 tsconfig.json 中指定不同的 baseUrl 或重命名函数目录。

    【讨论】:

    • 我遇到了完全相同的问题。在这件事上浪费了好几个小时。尚未尝试您的解决方案,但希望它会奏效。
    猜你喜欢
    • 2015-10-20
    • 2011-09-14
    • 2015-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多