简体   繁体   English

用graphql开玩笑,“插件/预设文件不允许导出对象,只能导出功能”

[英]Jest with graphql, “Plugin/Preset files are not allowed to export objects, only functions”

I'm trying to write some tests with JEST and graphql but am getting the following error no matter what I have in my .test.js files (even when having no code at all in it). 我正在尝试用JEST和graphql编写一些测试,但是无论我的.test.js文件中有什么(即使根本没有代码),也都会出现以下错误。

Plugin/Preset files are not allowed to export objects, only functions. 插件/预设文件不允许导出对象,只能导出功能。 In /Users/oscarstein/Documents/Projekt/Biljettsystem/ticketgo/system/node_modules/babel-preset-stage-2/lib/index.js 在/Users/oscarstein/Documents/Projekt/Biljettsystem/ticketgo/system/node_modules/babel-preset-stage-2/lib/index.js中

My .babelrc file looks as follows: 我的.babelrc文件如下所示:

{
    "presets": ["env", "stage-2"]
   }

So the error comes from me using the preset "stage-2" and when i remove it everything works fine with the tests. 因此,错误是由我使用预设的“ stage-2”引起的,当我删除它时,在测试中一切正常。 But since my application is built with stage-2 I was wondering if there is any workaround using both "stage-2" and getting the JEST tests to work? 但是,由于我的应用程序是使用Stage-2构建的,所以我想知道是否存在同时使用“ stage-2”和使JEST测试正常工作的解决方法?


package.json file package.json文件

{
  "name": "system",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "nodemon --exec babel-node index.js",
    "test": "jest"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "apollo-server": "^2.1.0",
    "apollo-server-express": "^2.1.0",
    "bcrypt": "^3.0.2",
    "body-parser": "^1.18.3",
    "cors": "^2.8.5",
    "dotenv": "^6.1.0",
    "express": "^4.16.4",
    "graphql": "^14.0.2",
    "jest": "^24.0.0",
    "jsonwebtoken": "^8.3.0",
    "mysql2": "^1.6.4",
    "nodemailer": "^4.6.8",
    "nodemon": "^1.18.6",
    "pg": "^7.6.0",
    "sequelize": "^4.41.1",
    "stripe": "^6.22.0"
  },
  "devDependencies": {
    "@babel/core": "^7.2.2",
    "babel-cli": "^6.26.0",
    "babel-preset-env": "^1.7.0",
    "babel-preset-stage-2": "^6.24.1"
  }
}

Babel 7 has different preset/plugin dependencies from previous versions. Babel 7具有与先前版本不同的预设/插件依赖性。 The link posted by LoudNoises shows how to update the dependencies. LoudNoises发布的链接显示了如何更新依赖关系。 In your case, npm i -D @babel/preset-env @babel/preset-stage-2 , and then update your .babelrc : 在您的情况下, npm i -D @babel/preset-env @babel/preset-stage-2 ,然后更新.babelrc

{
  "presets": ["@babel/env", "@babel/stage-2"]
}

暂无
暂无

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

相关问题 使用 JEST 和 Vue.js 失败“插件/预设文件不允许导出对象,只能导出函数。” - Fail with JEST and Vue.js "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 Babel Plugin/Preset 文件不允许导出对象,只能导出函数 - Babel Plugin/Preset files are not allowed to export objects, only functions Babel错误:插件/预设文件不允许导出对象,仅可导出功能 - Babel Error: Plugin/Preset files are not allowed to export objects, only functions 错误:插件/预设文件不允许导出对象,只能导出功能/ babel-preset-stage-0 - Error:Plugin /Preset files are not allowed to export objects,only functions/babel-preset-stage-0 gulp-babel插件错误:不允许插件/预设文件导出对象,仅导出功能 - Error in plugin gulp-babel: Plugin/Preset files are not allowed to export objects, only functions Babel-Loader Error Plugin/Preset 文件不允许导出对象,只能导出函数 - Babel-Loader Error 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 出现“错误:插件/预设文件不允许导出对象,只能导出功能。” 来自 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
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM