reactjs - 在 create-react-app 中使用“./Name”中的导出名称?
问题描述
我正在尝试将 React 应用程序移动到 Create-React-App 中,但努力让一些事情正常工作,并且不知道使用 Create-React-App 什么是允许的,什么是不允许的(关于自定义和添加额外的模块)。
目前,具有 React 应用程序源的 CRA 无法在以下位置编译:
export App from "./App/App"
有错误:
./src/containers/index.js
SyntaxError: /Volumes/Mexico/Workspace/create-react-app-test/myapp/src/containers/index.js: Support for the experimental syntax 'exportDefaultFrom' isn't currently enabled (1:8):
Add @babel/plugin-proposal-export-default-from (https://git.io/vb4yH) to the 'plugins' section of your Babel config to enable transformation.
我不想退出 CRA,我不相信我可以更改 Babel 配置,所以我不知道该怎么做。
CRA 是否支持这种语法?如果是这样,我应该怎么做才能让它工作。如果没有,我是否必须重写所有代码?
反应脚本 2.1.8 节点 v11.14.0 npm 6.9.0
谢谢,阿什利。
解决方案
export App from "./App/App"
不在受支持的export
语法变体中。
为了符合规范,可以将其更改为:
export { default as App } from "./App/App"
推荐阅读
- python - Python3从PID获取进程基地址
- jpa - 缺少序列信息
- firebase - 将 Firebase Auth 用户数据安全地存储在 Ionic Storage 中
- sql - 根据条件从查询响应中选择一条记录 | 函数 postgres
- networking - WebSockets 不适用于 GCP 中的 HTTP/2 负载均衡器后端
- java - ProcessorContext 的远程 forward() 调用抛出 NPE
- python - Python3 - 列表索引超出范围 - 从文件中提取数据
- c++ - 可以投个矢量图吗
到一个向量 - python - 基于辅助列值的颜色直方图,用于探索性分析
- javascript - 在 Javascript/jQuery 中使用 datetimepicker 在 HTML 表中过滤 FROM 和 TO 日期