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

質問編集履歴

2

文章訂正

2021/12/23 04:33

投稿

edu
edu

スコア35

title CHANGED
File without changes
body CHANGED
@@ -31,8 +31,8 @@
31
31
  ├── firebase.js
32
32
  ├── App.js
33
33
  firebase.js
34
-
35
34
  ```
35
+ ```
36
36
  //firebase.js
37
37
  import firebase from "firebase/app";
38
38
  import "firebase/app";
@@ -51,8 +51,8 @@
51
51
 
52
52
  export const auth = firebase.auth();
53
53
  export const db = firebaseApp.firestore();
54
-
55
54
  ```
55
+ ```
56
56
  //AuthProvider.js
57
57
 
58
58
  import React, { useEffect, useState } from "react";

1

文章訂正

2021/12/23 04:33

投稿

edu
edu

スコア35

title CHANGED
@@ -1,1 +1,1 @@
1
- 【React】エラー表示『TypeError: Cannot read properties of undefined (reading 'year')』を改善したい
1
+ 【React】エラー表示 Module not found: Can't resolve './firebase'』を改善したい
body CHANGED
@@ -1,166 +1,62 @@
1
- reactでwebフォームを作成しています。
1
+ reactで、Firebase使い、認証機能を作成しています。
2
2
 
3
- TypeError: Cannot read properties of undefined (reading 'year')』という表示を改善したいです。
3
+ Module not found: Can't resolve './firebase'』という表示を改善したいです。
4
+ ```
5
+ Failed to compile
4
- ※ terminal上は、『Compiled successfully!』と表示されます。
6
+ ./src/auth/AuthProvider.js
5
-
7
+ Module not found: Can't resolve './firebase'
8
+ ```
6
- エラー文を検索して、似たような感じもがなく、どのよう解決したらよくわかりません。
9
+ エラー文を検索して、下記サイト書いてある改善方法を実行したが、改善しませんでした
10
+ どのように解決したらよくわかりません。
7
11
  何方かアドバイスをお願いします。
8
12
 
9
13
  試したこと
10
- ① 『TypeError: Cannot read properties of undefined (reading 'year')』で、検索をしたが、似たようなものがなく何が原因かわからなかった。
14
+ ① 『Module not found: Can't resolve './firebase'』で、検索を、下記のサイトに書いてある改善方法を実行したが、
15
+ 改善しなかった。
11
16
 
17
+ ReactでModule not found: Can’t resolve ‘firebase/app’ in~の対処方法
18
+
19
+ Module not found: Can't resolve 'firebase' in
20
+
21
+ ディレクトリ構成
22
+
12
23
  ```
24
+ src
25
+ ├── auth
26
+ ├── AuthProvider.js
27
+ └── Login.js
28
+ └── PrivateRoute.js
29
+ └── SignUp.js
30
+ ├── components
13
- //Basic;.js
31
+ ├── firebase.js
32
+ ├── App.js
33
+ firebase.js
14
34
 
35
+ ```
36
+ //firebase.js
15
- import React from "react";
37
+ import firebase from "firebase/app";
38
+ import "firebase/app";
39
+ import "firebase/auth";
40
+ import "firebase/firestore";
41
+ import "firebase/database";
16
42
 
17
- import { Link } from "react-router-dom";
18
- import {
19
- FormControl,
20
- FormControlLabel,
43
+ firebase.initializeApp({
21
- FormLabel,
22
- InputLabel,
23
- Radio,
24
- RadioGroup,
25
- Select,
26
- } from "@mui/material";
44
+ apiKey: process.env.REACT_APP_FIREBASE_KEY,
45
+ authDomain: process.env.REACT_APP_FIREBASE_DOMAIN,
46
+ databaseURL: process.env.REACT_APP_FIREBASE_DATABASE,
27
- import { motion } from "framer-motion";
47
+ projectId: process.env.REACT_APP_FIREBASE_PROJECT_ID,
48
+ storageBucket: process.env.REACT_APP_FIREBASE_STORAGE_BUCKET,
49
+ messagingSenderId: process.env.REACT_APP_FIREBASE_SENDER_ID,
50
+ });
28
51
 
29
- const Basic = ({ basicProfile, setBasicProfile, isConfirm }) => {
30
- return (
31
- <>
32
- <motion.div
33
- initial={{ scaleY: 0 }}
34
- animate={{ scaleY: 1 }}
35
- exit={{ scaleY: 0 }}
36
- transition={{ duration: 0.5 }}
37
- >
38
- <div>
39
- <p>お客様の情報を入力して下さい</p>
40
- <div style={{ textAlign: "center" }}>
41
- <FormControl component="fieldset">
42
- <FormLabel component="gender">- 性別 -</FormLabel>
43
- {isConfirm ? (
44
- <span>{basicProfile?.gender === "male" ? "男性" : "女性"}</span>
45
- ) : (
46
- <RadioGroup
47
- row
48
- aria-label="gender"
49
- name="row-radio-buttons-group"
50
- value={basicProfile.gender}
51
- onChange={(evt) =>
52
- setBasicProfile((state) => {
53
- return { ...state, gender: evt.target.value };
54
- })
55
- }
56
- >
57
- <FormControlLabel
58
- value="male"
59
- control={<Radio />}
60
- label="男性"
61
- />
62
- <FormControlLabel
63
- value="female"
64
- control={<Radio />}
65
- label="女性"
66
- />
67
- </RadioGroup>
68
- )}
69
- </FormControl>
70
- </div>
71
- <div style={{ textAlign: "center" }}>
72
- <FormLabel component="legend">- 生年月日 -</FormLabel>
73
- <FormControl sx={{ m: 1, minWidth: 120 }}>
74
- <InputLabel htmlFor="grouped-native-select">year</InputLabel>
75
- {isConfirm ? (
76
- <span>{basicProfile.year}</span>
77
- ) : (
78
- <Select
79
- native
80
- defaultValue=""
81
- id="grouped-native-select"
82
- label="Grouping"
83
- value={basicProfile.year}
84
- onChange={(evt) =>
85
- setBasicProfile((state) => {
86
- return { ...state, year: evt.target.value };
87
- })
88
- }
89
- >
90
- <option aria-label="None" value="" />
91
- <optgroup label="year">
92
- {Array.from(Array(2020), (_, num) => (
93
- <option key={num} value={num + 1990}>
94
- {num + 1990}
95
- </option>
96
- ))}
97
- </optgroup>
98
- </Select>
99
- )}
100
- </FormControl>
101
- <FormControl sx={{ m: 1, minWidth: 120 }}>
102
- <InputLabel htmlFor="grouped-native-select">month</InputLabel>
103
- {isConfirm ? (
104
- <span>{basicProfile.month}</span>
105
- ) : (
106
- <Select
107
- native
108
- defaultValue=""
109
- id="grouped-native-select"
110
- label="Grouping"
111
- value={basicProfile.month}
112
- onChange={(evt) =>
113
- setBasicProfile((state) => {
114
- return { ...state, month: evt.target.value };
115
- })
116
- }
117
- >
118
- <option aria-label="None" value="" />
119
- <optgroup label="month">
120
- {Array.from(Array(12), (_, num) => (
121
- <option key={num} value={num + 1}>
122
- {num + 1}
123
- </option>
124
- ))}
125
- </optgroup>
126
- </Select>
127
- )}
128
- </FormControl>
129
- <FormControl sx={{ m: 1, minWidth: 120 }}>
130
- <InputLabel htmlFor="grouped-native-select">day</InputLabel>
131
- {isConfirm ? (
132
- <span>{basicProfile.day}</span>
133
- ) : (
134
- <Select
135
- native
136
- defaultValue=""
137
- id="grouped-native-select"
138
- label="Grouping"
139
- value={basicProfile.day}
140
- onChange={(evt) =>
141
- setBasicProfile((state) => {
142
- return { ...state, day: evt.target.value };
52
+ export const auth = firebase.auth();
143
- })
144
- }
145
- >
146
- <option aria-label="None" value="" />
147
- <optgroup label="day">
148
- {Array.from(Array(31), (_, num) => (
149
- <option key={num} value={num + 1}>
53
+ export const db = firebaseApp.firestore();
150
- {num + 1}
151
- </option>
152
- ))}
153
- </optgroup>
154
- </Select>
155
- )}
156
- </FormControl>
157
- </div>
158
- <Link to="/Questionnaire">次へ</Link>
159
- </div>
160
- </motion.div>
161
- </>
162
- );
163
- };
164
54
 
55
+ ```
165
- export default Basic;
56
+ //AuthProvider.js
57
+
58
+ import React, { useEffect, useState } from "react";
59
+ import { auth } from "./firebase";
60
+ import { db } from "./firebase";
61
+ import firebase from "./firebase";
166
62
  ```