Babel exception on all test

I am getting the following exception whenever I run a test. The application runs fine and I completed the Connection lab. What do I need to do to correct this? I won’t be able to execute any of the tests if I can’t fix this.

jest --passWithNoTests “db-connection”

Error: Plugin/Preset files are not allowed to export objects, only functions. In /Users/dj/dev/training/mongodb/university/m220js/mflix-js/node_modules/babel-preset-stage-1/lib/index.js
    at createDescriptor (/Users/dj/dev/training/mongodb/university/m220js/mflix-js/node_modules/@babel/core/lib/config/config-descriptors.js:178:11)
    at items.map (/Users/dj/dev/training/mongodb/university/m220js/mflix-js/node_modules/@babel/core/lib/config/config-descriptors.js:109:50)
    at Array.map (<anonymous>)
    at createDescriptors (/Users/dj/dev/training/mongodb/university/m220js/mflix-js/node_modules/@babel/core/lib/config/config-descriptors.js:109:29)
    at createPresetDescriptors (/Users/dj/dev/training/mongodb/university/m220js/mflix-js/node_modules/@babel/core/lib/config/config-descriptors.js:101:10)
    at presets (/Users/dj/dev/training/mongodb/university/m220js/mflix-js/node_modules/@babel/core/lib/config/config-descriptors.js:47:19)
    at mergeChainOpts (/Users/dj/dev/training/mongodb/university/m220js/mflix-js/node_modules/@babel/core/lib/config/config-chain.js:320:26)
    at /Users/dj/dev/training/mongodb/university/m220js/mflix-js/node_modules/@babel/core/lib/config/config-chain.js:283:7
    at buildRootChain (/Users/dj/dev/training/mongodb/university/m220js/mflix-js/node_modules/@babel/core/lib/config/config-chain.js:120:22)
    at loadPrivatePartialConfig (/Users/dj/dev/training/mongodb/university/m220js/mflix-js/node_modules/@babel/core/lib/config/partial.js:85:55)
npm ERR! Test failed.  See above for more details.
1 Like

From googling the error, it said something about old babel plugins or something. There’s also another question on this forum about the same thing (Outdated babel plugins). Copying my answer, but disclaimer: it can be wrong, it worked for me so far but I don’t know if it’s okay for the whole class and tickets I have not yet done.

I don’t know if this is correct, but after doing the following my test for connection passed (I am not sure about all the steps, I hope I don’t miss anything):
I uninstalled all the babel-xy in dev dependencies and then installed their updated versions (@babel/xy), so the babel-part of my package.json dev dependencies now looks like this:
@babel/core”: “^7.3.3”,
@babel/plugin-transform-runtime”: “^7.2.0”,
@babel/preset-env”: “^7.3.1”,
@babel/register”: “^7.0.0”,
@babel/runtime”: “^7.3.1”,

also, as you might see there is no -stage-1 because it threw an error as well, so I just uninstalled it. I don’t know if that will be problematic in the assignments to come, I have only completed one ticket so far.

As for the other changes I made, my .babelrc file looks like this:
{
“presets”: ["@babel/env"],
“plugins”: ["@babel/transform-runtime"]
}

and the first line of index.js is changed to
require("@babel/register")

I hope this helps, but again, it might not be correct thing to do since I only got it to work by trying and failing several times, I don’t exactly know what I should have done since I don’t know babel package well at all.

1 Like

Did you install the node dependencies ? run “npm install” and try again.

Thanks a lot Lucka_49415
I have the same issue, see the thread “All tests failed”.
Finally I moved to Babel 7.

For this:

  1. Delete node_modules directory
  2. Delete package-lock.json file in the root directory
  3. Delete all Babel 6 devDependencies from the package.json file
  4. Add new Babel 7 to the devDependencies:
    @babel/core”: “^7.3.3”,
    @babel/plugin-transform-runtime”: “^7.2.0”,
    @babel/preset-env”: “^7.3.1”,
    @babel/register”: “^7.0.0”,
    @babel/runtime”: “^7.3.1”,
  5. Change .babelrc content to:
    {
    “presets”: ["@babel/env"],
    “plugins”: ["@babel/transform-runtime"]
    }
  6. run installation:
    npm i

The tests for Chapter1 passed OK:
npm test -t db-connection
npm test -t projection
npm test -t text-subfield

Evgeny

6 Likes

I have read some other forum questions about the same problem and I noticed that my problem was running npm audit fix which, apparently, I shouldn’t have done. I will probably try to reinstall the original node modules and hopefully it will then work without any changes. They said to just ignore the vulnerabilities.

1 Like

Yes, the test environment works without fixing. But the “npm audit fix” is not an issue. It solves a potential issues in the future. )))

Plus one point:

4.2 Change index.js
require("@babel/register")

1 Like

Sure. Yuo are quite right.

Thanks a lot!
Now my code totally works!

Or rebuild the project without running “npm audit fix”.