0

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).

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

My .babelrc file looks as follows:

{
    "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. 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?


package.json file

{
  "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"
  }
}
Oscar
  • 221
  • 2
  • 7
  • 18
  • version matters. attach `package.json`'s `dependecies`/`devDependencies` – skyboyer Feb 05 '19 at 09:45
  • Did you happen to check out, https://stackoverflow.com/questions/47830273/babel-plugin-preset-files-are-not-allowed-to-export-objects-only-functions ? – Kyle Feb 05 '19 at 09:51
  • I attached the package.json file – Oscar Feb 05 '19 at 09:52
  • Yes, I looked over his solution but it didn't seem to mention anything about "stage-2" babel. – Oscar Feb 05 '19 at 09:54
  • what's the version of `@babel/core`? it is not in your `package.json` but I believe it should be installed(m.b. globally?) – skyboyer Feb 05 '19 at 17:28
  • Damn i must have missed it when copying, I added the version of babel/core im running. – Oscar Feb 05 '19 at 21:02

1 Answers1

0

Babel 7 has different preset/plugin dependencies from previous versions. The link posted by LoudNoises shows how to update the dependencies. In your case, npm i -D @babel/preset-env @babel/preset-stage-2, and then update your .babelrc:

{
  "presets": ["@babel/env", "@babel/stage-2"]
}
helloitsjoe
  • 6,264
  • 3
  • 19
  • 32