[英]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.我使用 create-react-app 创建了一个反应应用程序,它运行良好。 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";
然后我想使用react-select,所以我用yarn安装了它,添加了一个import语句,比如
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.我可以看到
type
关键字导致了问题,并怀疑它与名为flow
的东西有关,它似乎是 static 类型检查器。 What should I do to make it work?我应该怎么做才能让它工作?
Just import like就像导入一样
import Select from "react-select";
Please note that: import Select from "react-select";
请注意:
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:就我而言,在 VSCODE 中,有一些宏在调用时会生成如下内容:
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.
谨防。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.