質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.47%
ESLint

ESLintは、JavaScriptのための構文チェックツール。全検証ルールを自由に on/offでき、独自のプロジェクトに合わせたカスタムルールを容易に設定することが可能。公開されている様々なプラグインを組み込んで使用することもできます。

Firebase

Firebaseは、Googleが提供するBasSサービスの一つ。リアルタイム通知可能、並びにアクセス制御ができるオブジェクトデータベース機能を備えます。さらに認証機能、アプリケーションのログ解析機能などの利用も可能です。

React.js

Reactは、アプリケーションのインターフェースを構築するためのオープンソースJavaScriptライブラリです。

Q&A

解決済

1回答

2793閲覧

create-react-appでfirebase使用時のESLintの設定

madaratyou

総合スコア7

ESLint

ESLintは、JavaScriptのための構文チェックツール。全検証ルールを自由に on/offでき、独自のプロジェクトに合わせたカスタムルールを容易に設定することが可能。公開されている様々なプラグインを組み込んで使用することもできます。

Firebase

Firebaseは、Googleが提供するBasSサービスの一つ。リアルタイム通知可能、並びにアクセス制御ができるオブジェクトデータベース機能を備えます。さらに認証機能、アプリケーションのログ解析機能などの利用も可能です。

React.js

Reactは、アプリケーションのインターフェースを構築するためのオープンソースJavaScriptライブラリです。

0グッド

0クリップ

投稿2020/12/22 06:17

前提・実現したいこと

create-react-appでfirebase使用時のESLintにエラーがでるため、その解決法を知りたい。

Reactでcreate-react-appを使用し、firebase initfirebase deployをターミナルに打ち込み、firebase環境を構築しました。
その中で、firebase initをしたときに質問された、

A functions directory will be created in your project with a Node.js package pre-configured. Functions can be deployed with firebase deploy. ? What language would you like to use to write Cloud Functions? (Use arrow keys) ❯ JavaScript TypeScript

上記の質問にはTypeScriptを選びました。

また、ESLintの設定の質問には全てYesで答えました。

Do you want to use ESLint to catch probable bugs and enforce style? (Y/n) ✔ Wrote functions/package.json ✔ Wrote functions/.eslintrc.js ✔ Wrote functions/tsconfig.json ✔ Wrote functions/src/index.ts ✔ Wrote functions/.gitignore ? Do you want to install dependencies with npm now? (Y/n)

発生している問題・エラーメッセージ

Parsing error: Cannot read file '/users/uirikuto/googledrive/workspace/chatbot-demo/tsconfig.json'.

該当のソースコード

関連すると思われるファイルのコードを貼っておきます。

  • functions/.eslintrc.js
module.exports = { env: { browser: true, es6: true, node: true, }, extends: [ "react-app", "plugin:import/errors", "plugin:import/warnings", "plugin:import/typescript", ], parser: "@typescript-eslint/parser", parserOptions: { project: "tsconfig.json", sourceType: "module", }, plugins: [ "@typescript-eslint", "import", ], rules: { "@typescript-eslint/adjacent-overload-signatures": "error", "@typescript-eslint/no-empty-function": "error", "@typescript-eslint/no-empty-interface": "warn", "@typescript-eslint/no-floating-promises": "error", "@typescript-eslint/no-namespace": "error", "@typescript-eslint/no-unnecessary-type-assertion": "error", "@typescript-eslint/prefer-for-of": "warn", "@typescript-eslint/triple-slash-reference": "error", "@typescript-eslint/unified-signatures": "warn", "comma-dangle": ["error", "always-multiline"], "constructor-super": "error", eqeqeq: ["warn", "always"], "import/no-deprecated": "warn", "import/no-extraneous-dependencies": "error", "import/no-unassigned-import": "warn", "no-cond-assign": "error", "no-duplicate-case": "error", "no-duplicate-imports": "error", "no-empty": [ "error", { allowEmptyCatch: true, }, ], "no-invalid-this": "error", "no-new-wrappers": "error", "no-param-reassign": "error", "no-redeclare": "error", "no-sequences": "error", "no-shadow": [ "error", { hoist: "all", }, ], "no-throw-literal": "error", "no-unsafe-finally": "error", "no-unused-labels": "error", "no-var": "warn", "no-void": "error", "prefer-const": "warn", }, settings: { jsdoc: { tagNamePreference: { returns: "return", }, }, }, };
  • functions/tsconfig.json
{ "compilerOptions": { "module": "commonjs", "noImplicitReturns": true, "noUnusedLocals": true, "outDir": "lib", "sourceMap": true, "strict": true, "target": "es2017" }, "compileOnSave": true, "include": [ "src" ] }
  • functions/package.json
{ "name": "functions", "scripts": { "lint": "eslint \"src/**/*\"", "build": "tsc", "serve": "npm run build && firebase emulators:start --only functions", "shell": "npm run build && firebase functions:shell", "start": "npm run shell", "deploy": "firebase deploy --only functions", "logs": "firebase functions:log" }, "engines": { "node": "10" }, "main": "lib/index.js", "dependencies": { "firebase-admin": "^9.2.0", "firebase-functions": "^3.11.0" }, "devDependencies": { "@typescript-eslint/eslint-plugin": "^3.9.1", "@typescript-eslint/parser": "^3.8.0", "eslint": "^7.6.0", "eslint-plugin-import": "^2.22.0", "typescript": "^3.8.0", "firebase-functions-test": "^0.2.0" }, "private": true }
  • ルート直下のpackage.json
{ "name": "chatbot-demo", "version": "0.1.0", "private": true, "dependencies": { "@material-ui/core": "^4.11.2", "@material-ui/icons": "^4.11.2", "@material-ui/system": "^4.11.2", "@testing-library/jest-dom": "^5.11.6", "@testing-library/react": "^11.2.2", "@testing-library/user-event": "^12.6.0", "firebase": "^8.2.0", "react": "^17.0.1", "react-dom": "^17.0.1", "react-scripts": "4.0.1", "web-vitals": "^0.2.4" }, "scripts": { "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test", "eject": "react-scripts eject" }, "browserslist": { "production": [ ">0.2%", "not dead", "not op_mini all" ], "development": [ "last 1 chrome version", "last 1 firefox version", "last 1 safari version" ] } }

試したこと

.eslintrc.jsを↓のように変更しました。

parserOptions: { project: "tsconfig.json", tsconfigRootDir: __dirname, // この行を追加 sourceType: "module", },

しかし、さらなるエラーが出てしまいました。

Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser. The file does not match your project config: .eslintrc.js. The file must be included in at least one of the projects provided.

参考にした記事

https://stackoverflow.com/questions/64933543/parsing-error-cannot-read-file-tsconfig-json-eslint
https://wonwon-eater.com/ts-eslint-import-error/

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

解決方法

functions/.eslintrc.jsの1行目module.を削除したらなくなりました。

exports = { env: { browser: true, es6: true, node: true, }, extends: [ "react-app", "plugin:import/errors", "plugin:import/warnings", "plugin:import/typescript", ], parser: "@typescript-eslint/parser", parserOptions: { project: "tsconfig.json", tsconfigRootDir: __dirname, sourceType: "module", }, plugins: [ "@typescript-eslint", "import", ], rules: { "@typescript-eslint/adjacent-overload-signatures": "error", "@typescript-eslint/no-empty-function": "error", "@typescript-eslint/no-empty-interface": "warn", "@typescript-eslint/no-floating-promises": "error", "@typescript-eslint/no-namespace": "error", "@typescript-eslint/no-unnecessary-type-assertion": "error", "@typescript-eslint/prefer-for-of": "warn", "@typescript-eslint/triple-slash-reference": "error", "@typescript-eslint/unified-signatures": "warn", "comma-dangle": ["error", "always-multiline"], "constructor-super": "error", eqeqeq: ["warn", "always"], "import/no-deprecated": "warn", "import/no-extraneous-dependencies": "error", "import/no-unassigned-import": "warn", "no-cond-assign": "error", "no-duplicate-case": "error", "no-duplicate-imports": "error", "no-empty": [ "error", { allowEmptyCatch: true, }, ], "no-invalid-this": "error", "no-new-wrappers": "error", "no-param-reassign": "error", "no-redeclare": "error", "no-sequences": "error", "no-shadow": [ "error", { hoist: "all", }, ], "no-throw-literal": "error", "no-unsafe-finally": "error", "no-unused-labels": "error", "no-var": "warn", "no-void": "error", "prefer-const": "warn", }, settings: { jsdoc: { tagNamePreference: { returns: "return", }, }, }, };

投稿2020/12/22 08:53

madaratyou

総合スコア7

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.47%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問