我正在尝试实现用于实现Google OAuth登录的firestore / firebase功能,但一直说未导入firebase:
代码:
ERROR in node_modules/@angular/fire/auth/auth.d.ts:4:28 - error TS2307: Cannot find module 'firebase/app'.
4 import { User, auth } from 'firebase/app';
~~~~~~~~~~~~~~
node_modules/@angular/fire/firebase.app.module.d.ts:2:74 - error TS2307: Cannot find module 'firebase/app'.
2 import { auth, database, firestore, functions, messaging, storage } from 'firebase/app';
~~~~~~~~~~~~~~
node_modules/@angular/fire/firestore/collection-group/collection-group.d.ts:2:27 - error TS2307: Cannot find module 'firebase/app'.
2 import { firestore } from 'firebase/app';
~~~~~~~~~~~~~~
node_modules/@angular/fire/firestore/collection/collection.d.ts:2:27 - error TS2307: Cannot find module 'firebase/app'.
2 import { firestore } from 'firebase/app';
~~~~~~~~~~~~~~
node_modules/@angular/fire/firestore/document/document.d.ts:5:27 - error TS2307: Cannot find module 'firebase/app'.
5 import { firestore } from 'firebase/app';
~~~~~~~~~~~~~~
node_modules/@angular/fire/firestore/firestore.d.ts:8:27 - error TS2307: Cannot find module 'firebase/app'.
8 import { firestore } from 'firebase/app';
~~~~~~~~~~~~~~
node_modules/@angular/fire/firestore/interfaces.d.ts:2:27 - error TS2307: Cannot find module 'firebase/app'.
2 import { firestore } from 'firebase/app';
~~~~~~~~~~~~~~
src/app/services/auth.service.ts:4:22 - error TS2307: Cannot find module 'firebase/app'.
4 import { auth } from "firebase/app";
~~~~~~~~~~~~~~
我尝试过的事情:
我尝试重新安装@ angular / fire, 我试图将'firebase / app'更改为'./firebase/app', 我试图在StackOverflow上找到解决方案,但是什么也没有。
谢谢您的回答!
试图:安装角度型火力地堡,但: 它说了
node-pre-gyp WARN Using needle for node-pre-gyp https download
node-pre-gyp WARN Pre-built binaries not installable for grpc@1.24.0 and node@11.13.0 (node-v67 ABI, glibc) (falling back to source compile with node-gyp)
node-pre-gyp WARN Hit error EACCES: permission denied, mkdir '/usr/local/lib/node_modules/firebase/node_modules/grpc/src/node'
gyp WARN EACCES current user ("nobody") does not have permission to access the dev dir "/root/.cache/node-gyp/11.13.0"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/firebase/node_modules/grpc/.node-gyp"
gyp WARN install got an error, rolling back install
gyp WARN install got an error, rolling back install
gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/firebase/node_modules/grpc/.node-gyp'
gyp ERR! System Linux 4.18.0-25-generic
gyp ERR! command "/usr/local/lib/node_modules/node/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--library=static_library" "--module=/usr/local/lib/node_modules/firebase/node_modules/grpc/src/node/extension_binary/node-v67-linux-x64-glibc/grpc_node.node" "--module_name=grpc_node" "--module_path=/usr/local/lib/node_modules/firebase/node_modules/grpc/src/node/extension_binary/node-v67-linux-x64-glibc" "--napi_version=4" "--node_abi_napi=napi" "--napi_build_version=0" "--node_napi_label=node-v67"
gyp ERR! cwd /usr/local/lib/node_modules/firebase/node_modules/grpc
gyp ERR! node -v v11.13.0
gyp ERR! node-gyp -v v5.0.5
gyp ERR! not ok
node-pre-gyp ERR! build error
node-pre-gyp ERR! stack Error: Failed to execute '/usr/local/lib/node_modules/node/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --library=static_library --module=/usr/local/lib/node_modules/firebase/node_modules/grpc/src/node/extension_binary/node-v67-linux-x64-glibc/grpc_node.node --module_name=grpc_node --module_path=/usr/local/lib/node_modules/firebase/node_modules/grpc/src/node/extension_binary/node-v67-linux-x64-glibc --napi_version=4 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v67' (1)
node-pre-gyp ERR! stack at ChildProcess.<anonymous> (/usr/local/lib/node_modules/firebase/node_modules/grpc/node_modules/node-pre-gyp/lib/util/compile.js:83:29)
node-pre-gyp ERR! stack at ChildProcess.emit (events.js:193:13)
node-pre-gyp ERR! stack at maybeClose (internal/child_process.js:1001:16)
node-pre-gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:266:5)
node-pre-gyp ERR! System Linux 4.18.0-25-generic
node-pre-gyp ERR! command "/usr/local/lib/node_modules/node/bin/node" "/usr/local/lib/node_modules/firebase/node_modules/grpc/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build" "--library=static_library"
node-pre-gyp ERR! cwd /usr/local/lib/node_modules/firebase/node_modules/grpc
node-pre-gyp ERR! node -v v11.13.0
node-pre-gyp ERR! node-pre-gyp -v v0.13.0
node-pre-gyp ERR! not ok
Failed to execute '/usr/local/lib/node_modules/node/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --library=static_library --module=/usr/local/lib/node_modules/firebase/node_modules/grpc/src/node/extension_binary/node-v67-linux-x64-glibc/grpc_node.node --module_name=grpc_node --module_path=/usr/local/lib/node_modules/firebase/node_modules/grpc/src/node/extension_binary/node-v67-linux-x64-glibc --napi_version=4 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v67' (1)
npm WARN @angular/fire@5.2.1 requires a peer of @angular/common@>=6.0.0 <9 || ^9.0.0-0 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/fire@5.2.1 requires a peer of @angular/core@>=6.0.0 <9 || ^9.0.0-0 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/fire@5.2.1 requires a peer of @angular/platform-browser@>=6.0.0 <9 || ^9.0.0-0 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/fire@5.2.1 requires a peer of @angular/platform-browser-dynamic@>=6.0.0 <9 || ^9.0.0-0 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/fire@5.2.1 requires a peer of firebase@>= 5.5.7 <7 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/fire@5.2.1 requires a peer of rxjs@^6.0.0 but none is installed. You must install peer dependencies yourself.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! grpc@1.24.0 install: `node-pre-gyp install --fallback-to-build --library=static_library`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the grpc@1.24.0 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2019-10-16T13_45_44_371Z-debug.log
命令在sudo su中运行
答案 0 :(得分:1)
您还需要安装firebase
npm install firebase @angular/fire --save
答案 1 :(得分:1)
首先,您需要安装此软件:
npm install firebase @angular/fire --save
将Firebase配置添加到您的环境
export const environment = {
production: false,
// Your web app's Firebase configuration
firebaseConfig: {
apiKey: 'Api_key',
authDomain: 'domain',
databaseURL: '-------',
projectId: '------',
storageBucket: '',
messagingSenderId: 'hdhdhhdhd',
appId: 'didkdkdkkd'
}
};
然后在app.module.ts
import { AngularFireModule } from '@angular/fire';
import { AngularFireAuthModule } from '@angular/fire/auth';
从环境添加到import []和您的配置
imports: [
...,
AngularFireAuthModule,
AngularFireModule.initializeApp(environment.firebaseConfig),
]
然后将其导入您的服务
import { AngularFireAuth } from '@angular/fire/auth';
import { auth } from 'firebase/app';
然后使用
login() {
this.afAuth.auth.signInWithPopup(new auth.GoogleAuthProvider());
}