ReactのParsing error(ESLint)を解決したいです。
Q&A
Closed
解決したいこと
Reactを学ぶために、以下のサイトをみて、コードを書き写していました。
途中まで上手くいったのですが、コードを書いている途中にエラーが出てしまい、解決できません。
解決方法を教えてくださると幸いです。
発生している問題・エラー
$npx eslint App.js
(node:71563) [ESLINT_PERSONAL_CONFIG_SUPPRESS] DeprecationWarning: '~/.eslintrc.*' config files have been deprecated. Please remove it or add 'root:true' to the config files in your projects in order to avoid loading '~/.eslintrc.*' accidentally. (found in "../../.eslintrc.json")
(Use `node --trace-deprecation ...` to show where the warning was created)
/Users/ユーザー名/dog/src/App.js
39:11 error Parsing error: Unexpected token
37 | <div className="columns is-vcentered is-multiline">
38 | {urls.map((url) =>
> 39 | return (
| ^
40 | <div key={url} className="column is-3">
41 | <Image src={url} />
42 | </div>
✖ 1 problem (1 error, 0 warnings)
該当するソースコード
import React from "react";
function Header() {
return (
<header className="hero is-dark is-bold">
<div className="hero-body">
<div className="container">
<h1 className="title">Cute Dog Images</h1>
</div>
</div>
</header>
);
}
function Image(props) {
return (
<div className="card">
<div className="card-image">
<figure className="image">
<img src={props.src} alt="cute dog!" />
</figure>
</div>
</div>
);
}
function Loading(){
return <p>Loading...</p>;
}
function Gallery(props) {
const { urls } = props;
if (urls == null){
return <Loading />;
}
return (
<div className="columns is-vcentered is-multiline">
{urls.map((url) =>
return (
<div key={url} className="column is-3">
<Image src={url} />
</div>
)
)}
</div>
);
}
function Main() {
const urls = null;
return (
<main>
<section className="section">
<div calssName="container">
<Gallery urls={urls} />
</div>
</section>
</main>
);
}
function Footer() {
return (
<footer className="footer">
<div className="content has-text-centered">
<p>Dog images are retrieved from Dog API</p>
<p>
<a href="https://dog.ceo/dog-api/about">Donate to Dog API</a>
</p>
</div>
</footer>
);
}
function App() {
return (
<div>
<Header />
<Main />
<Footer />
</div>
);
}
export default App;
自分で試したこと
エラー内容を調べたところ、少し違いますがこのサイトの方法が似ていると思ったので、babel-eslint
をインストールしました。
ですが変わりませんでした。
.eslintrc.json
などを載せておきます。
.eslintrc.json
{
"env": {
"browser": true,
"es2021": true,
"es6": true
},
"parser":"babel-eslint",
"extends": [
"eslint:recommended",
"plugin:react/recommended"
],
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 2019,
"sourceType": "module"
},
"plugins": [
"react"
],
"settings": {
"react" : {
"version": "detect"
}
},
"rules": {
"semi":"warn",
"no-extra-semi":"warn",
"no-unused-vars":"warn",
"no-undef":"error",
"arrow-body-style": "error",
"arrow-parens": "error",
"arrow-spacing": "error",
"generator-star-spacing": "error",
"no-duplicate-imports": "error",
"no-useless-computed-key": "error",
"no-useless-constructor": "error",
"no-useless-rename": "error",
"no-var": "error",
"object-shorthand": "error",
"prefer-arrow-callback": "error",
"prefer-const": "error",
"prefer-rest-params": "error",
"prefer-spread": "error",
"prefer-template": "error",
"rest-spread-spacing": "error",
"template-curly-spacing": "error",
"yield-star-spacing": "error",
"react/jsx-uses-vars":1
}
}
package.json
{
"name": "dog",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.11.9",
"@testing-library/react": "^11.2.5",
"@testing-library/user-event": "^12.8.3",
"babel-eslint": "^10.1.0",
"bulma": "^0.9.2",
"eslint": "^7.22.0",
"eslint-plugin-react": "^7.22.0",
"prettier": "^2.2.1",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-scripts": "4.0.3",
"web-vitals": "^1.1.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
エラーのUnexpected token
のあとに何もないので、原因もわかりません。
教えていただけると幸いです。