gpt4 book ai didi

javascript - 语法错误 : Unexpected token, 预期 { (1 :7) , create-react-app

转载 作者:行者123 更新时间:2023-12-03 02:00:03 24 4
gpt4 key购买 nike

我使用 create-react-app 样板( https://github.com/facebook/create-react-app )启动了一个新的 React 项目,在尝试启动应用程序时出现以下错误,原因是我创建了一个名为“containers”的文件夹所有容器所在的位置,我想创建一个索引文件以从该目录导出所有容器,这样我就可以引用该目录来导入组件。

像这样:

从'./containers/UserContainer'导入UserContainer;//这个工作(但是丑陋)从 './containers' 导入 { UserContainer };//这不起作用

基本上,这是容器文件夹中我的 index.js 文件的内容:

export UserContainer from './UserContainer';

我收到错误语法错误:意外的标记,预期 { (1:7),

这是我的 package.json 的内容:

    {
"name": "user-management1",
"version": "0.1.0",
"private": true,
"dependencies": {
"install": "^0.11.0",
"npm": "^6.0.0",
"react": "^16.3.2",
"react-dom": "^16.3.2",
"react-redux": "^4.2.1",
"react-router-dom": "^4.2.2",
"react-router-redux": "^5.0.0-alpha.4",
"react-scripts": "1.1.4",
"redux": "^3.5.2"
},
"scripts": {
"lint": "eslint src",
"lint:fix": "npm run lint -- --fix",
"lint:css": "stylelint \"src/**/*.{css,less,scss,sss}\"",
"start": "npm run lint:fix && react-scripts start & npm run apiserver",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject",
"apiserver": "json-server --watch --port 4000 api/db.json"
},
"devDependencies": {
"bulma": "^0.7.1",
"eslint": "^3.19.0",
"eslint-config-airbnb": "^14.1.0",
"eslint-loader": "^1.7.1",
"eslint-plugin-css-modules": "^2.7.1",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^4.0.0",
"eslint-plugin-react": "^6.10.3",
"json-server": "^0.12.2"
}
}

我使用“react-scripts”启动应用程序。这个问题似乎与 babel 有关?我需要使用 babel-node 启动应用程序吗?或者在任何地方添加任何预设?我认为使用这个样板 babel 已经配置为在 ES6 中开始编码。

请帮忙

最佳答案

您基本上是在重新导出一个模块(即将另一个模块的导出添加到当前模块的导出中)。为了使模块 ./UserContainer 的命名导出 UserContainer 成为当前模块的默认导出,您应该编写:

export { default as UserContainer } from './UserContainer'

检查这个link完整引用

关于javascript - 语法错误 : Unexpected token, 预期 { (1 :7) , create-react-app,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50075381/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com