最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin5浏览0评论
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 pile.

./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 './ponents/Menu';
  6 | import isEqual from './internal/react-fast-pare';

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?

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 pile.

./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 './ponents/Menu';
  6 | import isEqual from './internal/react-fast-pare';

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?

Share Improve this question asked Apr 29, 2020 at 14:18 akanosenritu0akanosenritu0 313 bronze badges 1
  • Same problem here. – André Bonna Commented Apr 29, 2020 at 17:04
Add a ment  | 

2 Answers 2

Reset to default 11

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.

发布评论

评论列表(0)

  1. 暂无评论