While attempting to convert a PHP script to JavaScript using babel-preset-php
, I encountered the following error:
Error: Plugin 0 specified in "/media/deep/5738c180-2397-451b-b0b5-df09b7ad951e1/deepx/Documents/TestingAll/node_modules/babel-preset-php/src/index.js" provided an invalid property of "default" (While processing preset: "/media/deep/5738c180-2397-451b-b0b5-df09b7ad951e1/deepx/Documents/TestingAll/node_modules/babel-preset-php/src/index.js")
at Plugin.init (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/plugin.js:131:13)
at Function.normalisePlugin (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:152:12)
at /usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:184:30
at Array.map (<anonymous>)
at Function.normalisePlugins (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:158:20)
at OptionManager.mergeOptions (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:234:36)
at /usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:265:14
at /usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:323:22
at Array.map (<anonymous>)
at OptionManager.resolvePresets (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:275:20)
I installed the preset using npm i -S babel-preset-php
.
I configured my .babelrc
file like this:
{
"presets": ["php"]
}
In addition, I installed the Babel CLI with npm i -g babel-cli
. Then, I created a simple PHP file containing only basic code:
<?php
echo "hello world";
When trying to transpile the PHP file into JS using babel file.php -o file.js
, the aforementioned error occurs.
package.json
-
{
"name": "testingall",
"version": "1.0.0",
"description": "",
"main": "script.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^0.21.1",
"babel-core": "^6.26.3",
"babel-loader": "^8.2.2",
"babel-plugin-transform-flow-strip-types": "^6.22.0",
"babel-preset-php": "^2.0.0",
"body-parser": "^1.19.0",
"compression": "^1.7.4",
"cors": "^2.8.5",
"dotenv": "^9.0.2",
"express": "^4.17.1",
"express-rate-limit": "^5.2.6",
"pug": "^3.0.2",
"superagent": "^6.1.0"
}
}
Node version - v12.18.4
.
Babel version - 6.26.0 (babel-core 6.26.3)
Any suggestions on how to resolve this issue?