简体   繁体   中英

Error trying to import react-select to a project created with create-react-app

yarn create react-app
yarn add react-select

I created a react app using create-react-app, and it worked fine. Then I wanted to use react-select, so I installed it with yarn, added an import statement like import Select from "react-select/src/Select";

I got this error:

Failed to compile.

./node_modules/react-select/src/Select.js
SyntaxError: ~~~~\node_modules\react-select\src\Select.js: Unexpected token, expected "," (3:32)

  1 | // @flow
  2 | 
> 3 | import React, { Component, type ElementRef, type Node } from 'react';
    |                                 ^
  4 | import memoizeOne from 'memoize-one';
  5 | import { MenuPlacer } from './components/Menu';
  6 | import isEqual from './internal/react-fast-compare';

I can see the type keyword is causing the issue and suspect it has to do with something named flow which seems a static type checker. What should I do to make it work?

Just import like

import Select from "react-select";

Please note that: import Select from "react-select"; as above may not be enough!

In my case, in VSCODE there are macros that when invoked, generates someting like:

import { valueFocusAriaMessage } from 'react-select/src/accessibility'

Comment out / delete the line to solve the syntax error problem. I emphasize the issue since the line is added at the top, while you may not notice it. Beware.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM