Babel在导出聚合时抛出类型错误

编程入门 行业动态 更新时间:2024-10-25 18:28:53
本文介绍了Babel在导出聚合时抛出类型错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

运行gulp任务时,出现以下错误:

When running my gulp task, I get the following error:

SyntaxError in plugin "gulp-babel" Message: /Users/******/Repos/******/src/scripts/config/index.js: Unexpected export specifier type > 1 | export * as constants from './constants'; ^^^^^^^^^^^^^^

我不确定为什么会这样,因为我正在运行所需的插件以允许ES6导入/导出,或者我想...

I'm not sure why this is as I am running the required plugins to allow ES6 imports/exports, or so I thought...

.babelrc

{ "presets": [ "@babel/preset-env", "@babel/preset-react" ], "plugins": [ "add-module-exports", "@babel/plugin-transform-modules-commonjs", "@babel/plugin-proposal-class-properties", "@babel/plugin-proposal-export-default-from" ] }

package.json -我已包含完整列表,其中大多数可能无关紧要,但以防万一已知的软件包冲突.

package.json - I've included the full list, most of it will probably be irrelevant but just in case there are any known package conflicts.

"dependencies": { "@babel/polyfill": "^7.8.3", "classnames": "^2.2.5", "concurrent-transform": "^1.0.0", "deep-freeze": "0.0.1", "eslint": "^3.17.1", "eslint-plugin-babel": "^3.2.0", "eslint-plugin-react": "^6.10.0", "git-rev": "^0.2.1", "gulp-awspublish": "^4.0.0", "gulp-sftp": "^0.1.5", "moment": "^2.18.1", "moment-timezone": "^0.5.26", "path": "^0.12.7", "qs": "^6.4.0", "react": "^16.8.4", "react-addons-css-transition-group": "^15.0.2", "react-dom": "^16.8.4", "react-fastclick": "^3.0.2", "react-redux": "^4.4.5", "react-router": "^3.2.5", "react-router-redux": "^4.0.8", "react-string-replace": "^0.4.0", "react-transition": "^1.0.3", "react-transition-group": "^2.7.0", "redux": "^3.5.2", "redux-thunk": "^2.3.0", "underscore": "^1.8.3" }, "devDependencies": { "@babel/core": "^7.8.3", "@babel/plugin-proposal-class-properties": "^7.8.3", "@babel/plugin-proposal-export-default-from": "^7.8.3", "@babel/plugin-transform-modules-commonjs": "^7.8.3", "@babel/preset-env": "^7.8.3", "@babel/preset-es2015": "^7.0.0-beta.53", "@babel/preset-react": "^7.8.3", "axios": "^0.15.3", "babel-core": "^6.26.3", "babel-eslint": "^6.0.4", "babel-jest": "^25.1.0", "babel-loader": "^8.0.6", "babel-plugin-add-module-exports": "^1.0.2", "babel-polyfill": "^6.26.0", "babelify": "^9.0.0", "chai": "^3.5.0", "enzyme": "^2.7.1", "gulp": "^3.9.1", "gulp-autoprefixer": "^3.1.1", "gulp-babel": "^8.0.0", "gulp-browserify": "^0.5.1", "gulp-clean": "^0.3.2", "gulp-color": "0.0.1", "gulp-connect": "^5.0.0", "gulp-cssnano": "^2.1.2", "gulp-htmlmin": "^3.0.0", "gulp-livereload": "^3.8.1", "gulp-load-plugins": "^1.5.0", "gulp-mocha": "^4.3.0", "gulp-param": "^0.6.4", "gulp-rename": "^1.2.2", "gulp-sass": "^3.1.0", "gulp-sass-glob": "^1.0.8", "gulp-sourcemaps": "^2.4.1", "gulp-ssh": "^0.6.0", "gulp-streamify": "^1.0.2", "gulp-uglify": "^2.1.0", "gulp-watch": "^4.3.11", "gulp-webserver": "^0.9.1", "jest": "^25.1.0", "jsdom": "^9.12.0", "lint-staged": "^3.4.0", "mocha": "^3.2.0", "mocha-jsdom": "^1.1.0", "mocha-junit-reporter": "^1.13.0", "mock-require": "^2.0.1", "pre-commit": "^1.2.2", "prop-types": "^15.5.10", "react-addons-create-fragment": "^15.6.0", "react-addons-test-utils": "^15.6.0", "react-tools": "^0.13.3", "redux-mock-store": "^1.2.3", "run-sequence": "^1.2.2" }

任何帮助表示赞赏-我真的为此感到茫然.

Any help appreciated - I'm really at a loss for this one.

(使用节点v9.11.2)

(Using node v9.11.2)

推荐答案

来自此线程

问题是,我们通过"foo"支持添加了export * as ns 默认为@ babel/parser(在#10521中),而不是@ babel/preset-env.

The problem is that we added export * as ns from "foo" support by default to @babel/parser (in #10521) but not to @babel/preset-env.

作为解决方法,您可以启用 @ babel/plugin-proposal-export-namespace-来自您的配置.

As a workaround, you can enable @babel/plugin-proposal-export-namespace-from in your config.

因此,将@babel/plugin-proposal-export-namespace-from添加到您的.babelrc和dev依赖项中,您就可以了!

So add @babel/plugin-proposal-export-namespace-from to your .babelrc and dev dependencies and you should be OK!

看起来最终它将被内置到预设环境中,因此您不必使用插件.

It looks like eventually this will be built into the preset-env so you won't have to use a plugin.

更多推荐

Babel在导出聚合时抛出类型错误

本文发布于:2023-11-22 13:02:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1617515.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:抛出   错误   类型   Babel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!