SyntaxError: Select.js: Unexpected token, expected "," (3:32)
See original GitHub issueI tried to run the example code but React tells me that there’s a syntax error in the library:
My code (the example)
const options = [
{ value: 'chocolate', label: 'Chocolate' },
{ value: 'strawberry', label: 'Strawberry' },
{ value: 'vanilla', label: 'Vanilla' },
];
export default function App() {
const [selectedOption, setSelectedOption] = useState(null);
return (
<div className="App">
<Select
defaultValue={selectedOption}
onChange={setSelectedOption}
options={options}
/>
</div>
);
}
I’m using React 17.0.1 and react-select ^3.1.0.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7
Top Results From Across the Web
SyntaxError:Unexpected token, expected "," - Stack Overflow
You must place the map function in <React.Fragment> tag (equivalent: <> ). Additionally, the arguments should be destructed object.
Read more >Unexpected token error for catch JavaScript - GeeksforGeeks
Unexpected token error is usually regarded as a subset error of the main Syntax error which generally appears whenever we try executing a ......
Read more >Unexpected token, expected "," : r/reactjs - Reddit
Unexpected token, expected ",". Hey guys, I'm loading some data coming ... You are using a map , but your callback isn't valid...
Read more >SyntaxError: Unexpected token in JavaScript | bobbyhadz
Having a <script /> tag that points to an HTML file instead of a JS file. Getting an HTML response from a server...
Read more >SyntaxError: Unexpected token '=' in js on older Macs
Expected an opening '(' before a method's parameter list” Googling the error phrase gives the github explanation of the error. Many many people...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve found the solution !
vscode auto-import added this line :
import Select from 'react-select/src/Select;
But you actually need to import the Select component from react-select withimport Select from 'react-select
@realmayus It’s because the code is written in Flow, which is typing superset over Javascript. I think the problem is well readable from the screenshot you’ve attached – if you look on the line 3, above the
^
sign (which highlights the place where the error happened) you see there is keywordtype
which you do not know from JS world. Try to remove it and you’ll see what happens next.