Title: TestsNodejs - compilers deprecation in mocha and babel
Tags: node.js;mocha.js;tdd;babeljs
Question: I'm building api rest on node with integration test (Babel, chai, mocha)
I changed
--compilers js:babel-core/register
--require babel-core/register
as recommended by the documentation:
https://github.com/mochajs/mocha/wiki/compilers-deprecation
But when I make this change in my mocha.opts file, the error appears:
C:\Users\Ranulfo\Desktop\noderest&gt;npm run test-integration
&gt; gordonmatthew@example.org test-integration C:\Users\Ranulfo\Desktop\noderest
&gt; mocha --opts test/integration/mocha.opts test/integration/*.js
C:\Users\Ranulfo\Desktop\noderest\test\integration\helpers.js:1
(function (exports, require, module, __filename, __dirname) { import supertest f
rom 'supertest';
^^^^^^
SyntaxError: Unexpected token import
For more details of the code:
mocha.opts(test/integration/mocha):
--require test/integration/helpers.js
--reporter spec
--require babel-core/register
--slow 5000
helpers.js (test/integration/helpers.js)
import supertest from 'supertest';
import chai from 'chai';
import app from '../../app';
global.app = app;
global.request = supertest(app);
global.expect = chai.expect;
package.json
"name": "noderest",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "babel-node ./index.js",
"test": "echo \"Error: no test specified\" &amp;&amp; exit 1",
"test-integration": "mocha --opts test/integration/mocha.opts test/integration/*.js"
"author": "",
"license": "ISC",
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-preset-env": "^1.7.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-node6": "^11.0.0",
"babel-preset-stage-2": "^6.24.1",
"babel-register": "^6.26.0",
"chai": "^4.1.2",
"mocha": "^5.2.0",
"supertest": "^3.1.0"
"dependencies": {
"express": "^4.16.3",
"sequelize": "^4.37.10",
"sqlite3": "^4.0.0"
.babelrc
"presets": ["env"]
Comment: same issue. wondering if you ever resolved?

Comment: Yes, see my answer

Here is the accepted answer: With the update of "Babel" for version 7, the addition of some configuration steps has occurred.
To adjust the "bug" do the following steps:
Install the specified dependency:
npm install --save-dev @ babel / register
Change the "mocha.opts" file to the compilers for the following line:
--compilers js: @ babel / register
Once this is done, your workflow should be normalized. (I.e.
Note: Look out for the following dependencies that are not present in the tutorial.
npm install --save-dev @babel/cli
npm install --save-dev @babel/core
npm install --save-dev @babel/node
npm install --save-dev @babel/preset-env
npm install --save-dev @babel/register
Auxiliary content:
Setup: https://babeljs.io/setup#installation
Migration:  https://babeljs.io/docs/en/v7-migration
Mocha issues - Compilers deprecation https://github.com/mochajs/mocha/wiki/compilers-deprecation
Comment for this answer: Answer from Ashfaq nisar is spot-on, simple and concise.

Here is another answer: For the people who are just here due to the error of deprecation notice of using compilers and have no other issues with the babel.
Just install the dependency @babel/register.
And change the test script from mocha --compilers js:babel-core/register to mocha --require @babel/register
This should solve your error regarding the error notice from mocha.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 2, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2018:00:06/02/18', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<node.js><mocha.js><tdd><babeljs>', 'Title': 'TestsNodejs - compilers deprecation in mocha and babel', 'ViewCount': 2791, 'id': 50653904, 'user_AboutMe': None, 'user_AccountId': 12288297.0, 'user_DisplayName': 'Guilherme Lucas', 'user_Reputation': 467.0, 'user_Views': 48.0, 'user_id': 9085594.0}}