前提・実現したいこと
create-react-appでfirebase使用時のESLintにエラーがでるため、その解決法を知りたい。
Reactでcreate-react-appを使用し、firebase init
、firebase 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/
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。