简体   繁体   English

错误:插件/预设文件不允许导出对象,只能导出功能/ babel-preset-stage-0

[英]Error:Plugin /Preset files are not allowed to export objects,only functions/babel-preset-stage-0

I am having some problems with webpack/babel.First i install webpack,webpack-cli,webpack-dev-server,babel-loader,babel-core,babel-preset-env and it seems to be working fine.But when i install babel-polyfill and babel-preset-stage-0(because i want to be able to use async and await) i keep getting aforementioned error.I ve been struggling with this for days i would really appreciate if someone just told me which dependencies i need to install and what adjustments i need to make in my files.At this point i just want to be able to use modules and async and await for vanilla javascript apps. 我在使用webpack / babel时遇到一些问题。首先我安装了webpack,webpack-cli,webpack-dev-server,babel-loader,babel-core,babel-preset-env,它似乎工作正常。但是当我安装时babel-polyfill和babel-preset-stage-0(因为我想能够使用async和await)我一直遇到上述错误。我已经为此苦苦挣扎了好几天了,如果有人告诉我我有哪些依赖关系,我将不胜感激。需要安装以及我的文件需要进行哪些调整。目前,我只想能够使用模块并异步处理并等待香草javascript应用程序。

 // ./src/app.js async function getUsers() { const response = await fetch("https://jsonplaceholder.typicode.com/users"); const data = await response.json(); return data; } getUsers().then(data => console.log(data)); //Package json file { "name": "new", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \\"Error: no test specified\\" && exit 1", "build": "webpack", "start": "webpack-dev-server --output-public-path=/build/" }, "author": "", "license": "ISC", "devDependencies": { "@babel/core": "^7.2.2", "@babel/preset-env": "^7.2.3", "babel-loader": "^8.0.5", "babel-polyfill": "^6.26.0", "babel-preset-stage-0": "^6.24.1", "webpack": "^4.28.4", "webpack-cli": "^3.2.1", "webpack-dev-server": "^3.1.14" } } //webpack.config.js const path = require("path"); module.exports = { mode: "production", entry: { app: ["babel-polyfill", "./src/app.js"] }, output: { path: path.resolve(__dirname, "build"), filename: "app.bundle.js" }, module: { rules: [ { test: /\\.m?js$/, exclude: /(node_modules|bower_components)/, use: { loader: "babel-loader", options: { presets: ["@babel/preset-env", "stage-0"] } } } ] } }; 
 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta http-equiv="X-UA-Compatible" content="ie=edge" /> <title>Document</title> </head> <body> <script src="./build/app.bundle.js"></script> </body> </html> 

Check if you have multiple Babel installations. 检查您是否安装了多个Babel。

In my case I had one at my project's node_modules folder and another global. 就我而言,我在项目的node_modules文件夹中有一个,而在全局中又有一个。

Uninstalling my global @babel at ~/node_modules solved this issue here. ~/node_modules 卸载我的全局@babel ~/node_modules解决此问题。

我下载了Brad Traversy的babel_webpack_starter包,它为我解决了这个问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Babel错误:插件/预设文件不允许导出对象,仅可导出功能 - Babel Error: Plugin/Preset files are not allowed to export objects, only functions Babel Plugin/Preset 文件不允许导出对象,只能导出函数 - Babel Plugin/Preset files are not allowed to export objects, only functions gulp-babel插件错误:不允许插件/预设文件导出对象,仅导出功能 - Error in plugin gulp-babel: Plugin/Preset files are not allowed to export objects, only functions 出现“错误:插件/预设文件不允许导出对象,只能导出功能。” 来自 babel-preset-react-app/index.js - Getting "Error: Plugin/Preset files are not allowed to export objects, only functions." from babel-preset-react-app/index.js Babel-Loader Error Plugin/Preset 文件不允许导出对象,只能导出函数 - Babel-Loader Error Plugin/Preset files are not allowed to export objects, only functions 反应错误:不允许插件/预设文件导出对象,仅导出功能 - error on react: Plugin/Preset files are not allowed to export objects, only functions 用graphql开玩笑,“插件/预设文件不允许导出对象,只能导出功能” - Jest with graphql, “Plugin/Preset files are not allowed to export objects, only functions” “ npm start”抛出错误:不允许插件/预设文件导出对象,仅导出功能 - “npm start” throws Error: Plugin/Preset files are not allowed to export objects, only functions 错误:插件/预设文件不允许导出对象,只能导出功能。 ReactJS - Error: Plugin/Preset files are not allowed to export objects, only functions. ReactJS 在Webpack中配置Babel-preset-stage-0 - Config Babel-preset-stage-0 in Webpack
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM