前提・実現したいこと
Firebase FunctionsでFirestore Full-Text Searchを使用して全文検索を実装したいです。
発生している問題・エラーメッセージ
Firebase Functionsのログに以下のエラーメッセージが表示されます。
Functionsのデプロイ時にはローカルのコンソールにもFunctionsのログにもエラーメッセージはありません。
onAuthorUpdateContent Error: ENOENT: no such file or directory, open '/workspace/node_modules/firestore-full-text-search/node_modules/kuromoji/dict/base.dat.gz'
該当のソースコード
TypeScript
1import * as functions from "firebase-functions"; 2import * as admin from 'firebase-admin'; 3import firebase from "firebase"; 4import FirestoreFullTextSearch from "firestore-full-text-search"; 5 6admin.initializeApp(); 7const firestore = admin.firestore(); 8const contentsSearch = new FirestoreFullTextSearch(firestore.collection('contentsIndex')); 9 10interface ContentData { 11 // document field 12 // 省略 13} 14 15interface RootContentData extends ContentData { 16 authorRef: FirebaseFirestore.DocumentReference; 17} 18 19export const onAuthorUploadContent = functions.firestore.document('/authors/{authorId}/contents/{contentId}').onCreate(async (snapshot) => { 20 if (snapshot.ref.parent.parent) 21 await copyToRootWithContentSnapshot(snapshot, snapshot.ref.parent.parent); 22}); 23 24export const onAuthorUpdateContent = functions.firestore.document('/authors/{authorId}/contents/{contentId}').onUpdate(async (change) => { 25 if (change.after.ref.parent.parent) 26 await copyToRootWithContentSnapshot(change.after, change.after.ref.parent.parent); 27}); 28 29async function copyToRootWithContentSnapshot(snapshot: FirebaseFirestore.DocumentSnapshot, authorRef: FirebaseFirestore.DocumentReference) { 30 const contentId = snapshot.id; 31 const content = {...snapshot.data(), authorRef: authorRef} as RootContentData; 32 const batch = firestore.batch(); 33 const docRef = firestore.collection("contents").doc(contentId); 34 batch.set(docRef, content, { merge: true}); 35 await contentsSearch.set("ja", docRef, {batch, data: content}); 36 await batch.commit(); 37}
試したこと
ローカルの/functionsでnpm install及びnpm updateを行いましたが、変化はありませんでした。
補足情報(FW/ツールのバージョンなど)
package.json
JSON
1{ 2 "name": "functions", 3 "scripts": { 4 "lint": "eslint --ext .js,.ts .", 5 "build": "tsc", 6 "serve": "npm run build && firebase emulators:start --only functions", 7 "shell": "npm run build && firebase functions:shell", 8 "start": "npm run shell", 9 "deploy": "firebase deploy --only functions", 10 "logs": "firebase functions:log" 11 }, 12 "engines": { 13 "node": "14" 14 }, 15 "main": "lib/index.js", 16 "dependencies": { 17 "firebase-admin": "^9.11.1", 18 "firebase-functions": "^3.15.5", 19 "firestore-full-text-search": "^0.6.0" 20 }, 21 "devDependencies": { 22 "@typescript-eslint/eslint-plugin": "^3.9.1", 23 "@typescript-eslint/parser": "^3.8.0", 24 "eslint": "^7.6.0", 25 "eslint-config-google": "^0.14.0", 26 "eslint-plugin-import": "^2.24.2", 27 "firebase-functions-test": "^0.2.0", 28 "typescript": "^3.8.0" 29 }, 30 "private": true 31}
package-lock.json (一部省略)
JSON
1{ 2 "name": "functions", 3 "requires": true, 4 "lockfileVersion": 1, 5 "dependencies": { 6 "firestore-full-text-search": { 7 "version": "0.6.0", 8 "resolved": "https://registry.npmjs.org/firestore-full-text-search/-/firestore-full-text-search-0.6.0.tgz", 9 "integrity": "sha512-AAIJEx++GumxawydP22UfJukixMVuY3MhclOxNroBt7uI1VAS0FQabmQ5qEMZmwoh10+JShaAgkIe0SHVOGcBQ==", 10 "requires": { 11 "@opentelemetry/api": "^0.14.0", 12 "firebase-admin": "^9.4.2", 13 "firebase-functions": "^3.13.0", 14 "kuromoji": "^0.1.2", 15 "luxon": "^1.25.0" 16 } 17 }, 18 "kuromoji": { 19 "version": "0.1.2", 20 "resolved": "https://registry.npmjs.org/kuromoji/-/kuromoji-0.1.2.tgz", 21 "integrity": "sha512-V0dUf+C2LpcPEXhoHLMAop/bOht16Dyr+mDiIE39yX3vqau7p80De/koFqpiTcL1zzdZlc3xuHZ8u5gjYRfFaQ==", 22 "requires": { 23 "async": "^2.0.1", 24 "doublearray": "0.0.2", 25 "zlibjs": "^0.3.1" 26 } 27 }, 28 } 29}
あなたの回答
tips
プレビュー