我正试图用Nuxt消耗一个Firestore数据库。但是下面的代码在编译时产生了一个错误.我从我正在做的项目中留下了几个节选的内容。
在这个文件中,我配置了数据库的凭证路径。
README.md
$env:GOOGLE_APPLICATION_CREDENTIALS="D:\Educacion\Proyectos\Go\social\whatsapp-f91a0.json"
nuxt.config.js
plugins: [
'@plugins/firebase.js'
],
插件
火库.js
var admin = require("firebase-admin");
var serviceAccount = require("whatsapp-f91a0.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://whatsapp-f91a0.firebaseio.com"
});
const db = admin.database();
export {db}
索引.vue
<script>
import db from 'firebase';
db.collection('categorias').doc('aaa').get()
.then(doc=>{
if (!doc.exists){
console.log('no existe')
}
})
.catch(err=>{
console.error('error', err);
process.exit();
});
</script>
在这里,我在编译时得到一个错误
错误
WARN Compiled with 3 warnings friendly-errors 17:54:45
WARN in ./node_modules/hash-stream-validation/index.js friendly-errors 17:54:45
Module not found: Error: Can't resolve 'fast-crc32c' in 'D:\Educacion\Proyectos\Go\social\node_modules\hash-stream-validation' friendly-errors 17:54:45
friendly-errors 17:54:45
WARN in ./node_modules/retry-request/index.js friendly-errors 17:54:45
Module not found: Error: Can't resolve 'request' in 'D:\Educacion\Proyectos\Go\social\node_modules\retry-request' friendly-errors 17:54:45
friendly-errors 17:54:45
WARN in ./node_modules/configstore/node_modules/write-file-atomic/index.js friendly-errors 17:54:45
Module not found: Error: Can't resolve 'worker_threads' in 'D:\Educacion\Proyectos\Go\social\node_modules\configstore\node_modules\write-file-atomic'
friendly-errors 17:54:45
ERROR Failed to compile with 20 errors friendly-errors 17:54:45
These dependencies were not found: friendly-errors 17:54:45
friendly-errors 17:54:45
* child_process in ./node_modules/google-auth-library/build/src/auth/googleauth.js friendly-errors 17:54:45
* dns in ./node_modules/@grpc/grpc-js/build/src/resolver-dns.js friendly-errors 17:54:45
WARN in ./node_modules/configstore/node_modules/write-file-atomic/index.js friendly-errors 17:54:45
Module not found: Error: Can't resolve 'worker_threads' in 'D:\Educacion\Proyectos\Go\social\node_modules\configstore\node_modules\write-file-atomic'
friendly-errors 17:54:45
ERROR Failed to compile with 20 errors friendly-errors 17:54:45
These dependencies were not found: friendly-errors 17:54:45
friendly-errors 17:54:45
* child_process in ./node_modules/google-auth-library/build/src/auth/googleauth.js friendly-errors 17:54:45
* dns in ./node_modules/@grpc/grpc-js/build/src/resolver-dns.js friendly-errors 17:54:45
* fs in ./node_modules/@google-cloud/storage/build/src/file.js, ./node_modules/@grpc/grpc-js/build/src/tls-helpers.js and 8 others friendly-errors 17:54:45
* http2 in ./node_modules/@grpc/grpc-js/build/src/server.js friendly-errors 17:54:45
* net in ./node_modules/@grpc/grpc-js/build/src/resolver-dns.js, ./node_modules/http-proxy-agent/dist/agent.js and 1 other friendly-errors 17:54:45
* tls in ./node_modules/@grpc/grpc-js/build/src/channel-credentials.js, ./node_modules/http-proxy-agent/dist/agent.js and 1 other friendly-errors 17:54:46
* whatsapp-f91a0.json in ./plugins/firebase.js
谁能帮帮我?
Nuxt是一个前端框架,其目标是以多种方式(包括服务器端)来服务内容。
Firebase-admin是一个服务器端库。你可以在这里和那里做一些调整来使它工作,但这根本不值得推荐,首先你必须公开你的证书。
使用 Firebase Javascript SDK 可选择与 Firebase-Nuxt 集合 规则和认证索赔,所以你可以作为管理员工作。