1

I have already installed all the latest LTS versions of Babel but everytime I try Mocha this error is throwed. I suspect there is some dependency that is calling it, but if that's the case I have no idea what can be done.

I'm using Mocha and Chai to (try to) test my units. Thing is, everytime I run test the Requires Babel "^7.0.0-0", but was loaded with "6.26.3". error is throwed. I already updated babel-core and babel-register to their @ versions and even uninstalled the old ones but nothing changes. I have also tried to change my test script from:

"test": "nyc ./node_modules/.bin/mocha tests/**/*.spec.js --require babel-register"

To:

"test": "nyc ./node_modules/.bin/mocha tests/**/*.spec.js --require @babel-register"

But it misses the module.

In my research I have only seen fixes for Jest - not for Mocha. In case the error persists I think I'll be going to change testing frameworks.

I have also found a similar question here in Stack Overflow but no answer was given.

Here is my devDependecies:

"devDependencies": {
    "@babel/core": "^7.4.3",
    "@babel/plugin-transform-destructuring": "^7.4.3",
    "@babel/register": "^7.4.0",
    "babel-loader": "^8.0.5",
    "babel-preset-env": "^1.7.0",
    "chai": "^4.2.0",
    "eslint": "^5.16.0",
    "eslint-config-airbnb-base": "^13.1.0",
    "eslint-plugin-import": "^2.16.0",
    "husky": "^1.3.1",
    "mocha": "^6.1.3",
    "nyc": "^13.3.0",
    "prettier": "^1.17.0",
    "prettier-eslint": "^8.8.2",
    "prettier-eslint-cli": "^4.7.1",
    "webpack": "^4.29.6",
    "webpack-cli": "^3.3.0",
    "webpack-dev-server": "^3.3.1"
  }

If possible, I would like to keep using Mocha, so if anyone could help me out of this I would very much appreciate.

EDIT: Here is my .babelrc file:

{
  "plugins": ["@babel/plugin-transform-destructuring"],
  "presets": ["@babel/preset-env"]
}
Henrique Guerra
  • 233
  • 1
  • 13
  • Possible duplicate of [Upgrade to Babel 7: Cannot read property 'bindings' of null](https://stackoverflow.com/questions/52092739/upgrade-to-babel-7-cannot-read-property-bindings-of-null) – connexo Apr 17 '19 at 18:08
  • The `presets` on `.babelrc` is already setted as `@babel/preset-env`. – Henrique Guerra Apr 17 '19 at 18:47
  • 1
    `"babel-preset-env": "^1.7.0",` is still in your `devDependencies` while `@babel/preset-env` is not. – connexo Apr 17 '19 at 19:11
  • Oh, you are right. Unfortunaelly now Mocha is missing `babel-register` (I have installed and uninstalled it sometimes to doublecheck and even remade the `package-lock` file but nothing works. – Henrique Guerra Apr 17 '19 at 19:27
  • there is `@babel/register`, but I am still trying to get this working myself. :-\ – NullVoxPopuli Apr 18 '19 at 12:05
  • I finally made it work. Installed `@babel/preset-env` and `@babel/register` locally on the project and fixed the script test to `./node_modules/.bin/mocha tests/**/*.spec.js --require @babel/register`. – Henrique Guerra Apr 18 '19 at 12:37

0 Answers0