teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

5

タイトルの変更

2021/01/21 09:03

投稿

junsuke
junsuke

スコア1

title CHANGED
@@ -1,1 +1,1 @@
1
- Error occurred while parsing your function triggers
1
+ Typescript react firebase 環境でのエラー
body CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Typescript react firebase でチャットボット を作成中
4
4
  firebase functionsでチャットの構造体(json)をfirestoreにデプロイしたいです。
5
-
5
+ ソースコード
6
6
  ```
7
7
  import * as functions from 'firebase-functions'; ←ここでエラー発生 外部からインポートできませんみたいなことを言われています。
8
8
  import * as admin from "firebase-admin";

4

書式の改善

2021/01/21 09:03

投稿

junsuke
junsuke

スコア1

title CHANGED
File without changes
body CHANGED
@@ -3,6 +3,35 @@
3
3
  Typescript react firebase でチャットボット を作成中
4
4
  firebase functionsでチャットの構造体(json)をfirestoreにデプロイしたいです。
5
5
 
6
+ ```
7
+ import * as functions from 'firebase-functions'; ←ここでエラー発生 外部からインポートできませんみたいなことを言われています。
8
+ import * as admin from "firebase-admin";
9
+ admin.initializeApp();
10
+ const db = admin.firestore();
11
+
12
+ const sendResponse = (response: functions.Response, statusCode: number, body: any) => {
13
+ response.send({
14
+ statusCode,
15
+ body: JSON.stringify(body)
16
+ });
17
+ };
18
+
19
+
20
+ export const addDataset = functions.https.onRequest(async (req: any, res: any) => {
21
+ if (req.method !== 'POST') {
22
+ sendResponse(res, 405, {error: "Invalid Request"})
23
+ } else {
24
+ const dataset = req.body;
25
+ for (const key of Object.keys(dataset)) {
26
+ const data = dataset[key];
27
+ await db.collection('questions').doc(key).set(data)
28
+ }
29
+ sendResponse(res, 200, {message: 'Successfully added dataset! WooHoo!'});
30
+ }
31
+ });
32
+ ```
33
+
34
+
6
35
  ### 発生している問題・エラーメッセージ
7
36
  デプロイコマンドで途中までうまく行きますが、functions preparing functions directory for uploadingのとこでError発生します。
8
37
  ¥firebase deploy 以下エラーコード

3

書式の改善

2021/01/21 09:00

投稿

junsuke
junsuke

スコア1

title CHANGED
File without changes
body CHANGED
@@ -5,8 +5,9 @@
5
5
 
6
6
  ### 発生している問題・エラーメッセージ
7
7
  デプロイコマンドで途中までうまく行きますが、functions preparing functions directory for uploadingのとこでError発生します。
8
- firebase deploy 
8
+ ¥firebase deploy 以下エラーコード
9
+
9
-
10
+ ```
10
11
  i deploying firestore, functions, hosting
11
12
  i firestore: reading indexes from firestore.indexes.json...
12
13
  i cloud.firestore: checking firestore.rules for compilation errors...
@@ -36,14 +37,18 @@
36
37
  at /usr/local/lib/node_modules/firebase-tools/lib/triggerParser.js:19:15
37
38
  at Object.<anonymous> (/usr/local/lib/node_modules/firebase-tools/lib/triggerParser.js:57:3)
38
39
  at Module._compile (internal/modules/cjs/loader.js:1063:30)
40
+ ```
39
41
 
40
42
 
43
+
41
44
  ### 試したこと
42
45
  スタックオーバーフローに載っているものは全て試しました。
43
46
 
44
47
  ■追記 package.json tsconfig.jsonを追記しました
45
48
 
46
49
  package.json
50
+ ```
51
+
47
52
  {
48
53
  "name": "functions",
49
54
  "type":"module",
@@ -71,8 +76,10 @@
71
76
  "private": true
72
77
 
73
78
  }
79
+ ```
74
80
 
75
81
  tsconfig.json
82
+ ```
76
83
  {
77
84
  "compilerOptions": {
78
85
  "module": "commonjs",
@@ -87,4 +94,5 @@
87
94
  "include": [
88
95
  "src"
89
96
  ]
90
- }
97
+ }
98
+ ```

2

文法の修正

2021/01/21 07:16

投稿

junsuke
junsuke

スコア1

title CHANGED
File without changes
body CHANGED
@@ -1,11 +1,11 @@
1
1
  ### 前提・実現したいこと
2
2
 
3
- ここに質問の内容を詳しく書いてください。
4
3
  Typescript react firebase でチャットボット を作成中
5
4
  firebase functionsでチャットの構造体(json)をfirestoreにデプロイしたいです。
6
5
 
7
6
  ### 発生している問題・エラーメッセージ
7
+ デプロイコマンドで途中までうまく行きますが、functions preparing functions directory for uploadingのとこでError発生します。
8
- firebase deploy
8
+ firebase deploy 
9
9
 
10
10
  i deploying firestore, functions, hosting
11
11
  i firestore: reading indexes from firestore.indexes.json...

1

package.json tsconfig.jsonを追記しました

2021/01/21 07:10

投稿

junsuke
junsuke

スコア1

title CHANGED
File without changes
body CHANGED
@@ -39,4 +39,52 @@
39
39
 
40
40
 
41
41
  ### 試したこと
42
- スタックオーバーフローに載っているものは全て試しました。
42
+ スタックオーバーフローに載っているものは全て試しました。
43
+
44
+ ■追記 package.json tsconfig.jsonを追記しました
45
+
46
+ package.json
47
+ {
48
+ "name": "functions",
49
+ "type":"module",
50
+ "scripts": {
51
+ "lint": "tslint --project tsconfig.json",
52
+ "build": "tsc",
53
+ "serve": "npm run build && firebase emulators:start --only functions",
54
+ "shell": "npm run build && firebase functions:shell",
55
+ "start": "npm run shell",
56
+ "deploy": "firebase deploy --only functions",
57
+ "logs": "firebase functions:log"
58
+ },
59
+ "engines": {
60
+ "node": "12"
61
+ },
62
+ "main": "src/index.ts",
63
+ "dependencies": {
64
+ "firebase-admin": "^9.2.0",
65
+ "firebase-functions": "^3.11.0"
66
+ },
67
+ "devDependencies": {
68
+ "typescript": "^3.8.0",
69
+ "firebase-functions-test": "^0.2.0"
70
+ },
71
+ "private": true
72
+
73
+ }
74
+
75
+ tsconfig.json
76
+ {
77
+ "compilerOptions": {
78
+ "module": "commonjs",
79
+ "noImplicitReturns": true,
80
+ "noUnusedLocals": true,
81
+ "outDir": "lib",
82
+ "sourceMap": true,
83
+ "strict": true,
84
+ "target": "es2017"
85
+ },
86
+ "compileOnSave": true,
87
+ "include": [
88
+ "src"
89
+ ]
90
+ }