question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SyntaxError: Select.js: Unexpected token, expected "," (3:32)

See original GitHub issue

I tried to run the example code but React tells me that there’s a syntax error in the library: image

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:closed
  • Created 3 years ago
  • Comments:7

github_iconTop GitHub Comments

100reactions
trodixcommented, Dec 12, 2020

@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 keyword type which you do not know from JS world. Try to remove it and you’ll see what happens next.

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 with import Select from 'react-select

11reactions
dakurcommented, Nov 16, 2020

@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 keyword type which you do not know from JS world. Try to remove it and you’ll see what happens next.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found