"scripts": {
"test-1": "mocha --require @babel/register ./src/tests/stage1.spec.js",
"test-2": "mocha --require @babel/register ./src/tests/stage2.spec.js"
},
"dependencies": {
"@babel/core": "^7.2.2",
"@babel/node": "^7.2.2",
"@babel/preset-env": "^7.2.3",
"chai": "^4.2.0",
"mocha": "^5.2.0"
},
"devDependencies": {
"@babel/plugin-proposal-optional-chaining": "^7.16.7"
},
"babel": {
"presets": [
"@babel/preset-env"
],
"plugins": [
[
"@babel/plugin-proposal-optional-chaining"
]
]
}
Here are most parts of my package.json file, my Node version is 10, after npm run test-1, it will throw an error that
Support for the experimental syntax 'optionalChaining' isn't currently enabled (14:36):
12 | let existedIndex = null;
13 | this.crops.some((existedCrop, index) => {
> 14 | if (existedCrop.name === crop?.name) {
| ^
15 | existedIndex = index;
16 | return true;
17 | }
Add @babel/plugin-proposal-optional-chaining (https://git.io/vb4Sk) to the 'plugins' section of your Babel config to enable transformation.
I have executed npm i before, it seems that this plugin @babel/plugin-proposal-optional-chaining is not correctly loaded by @babel/register.
Where is the mistake?