首页 > 解决方案 > 在 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

谢谢,阿什利。

标签: reactjscreate-react-app

解决方案


export App from "./App/App"不在受支持的export语法变体中。

为了符合规范,可以将其更改为:

export { default as App } from "./App/App"

推荐阅读