After installing Babel in a backend project, it started to have a weird behavior.
All the libraries that were already installed and used in project, were using import statement, but now, only accept require method.
This is really strange, because it has situations where there are both calling methods at the same place.
For example at server.ts file:
const cors = require('cors');
import 'dotenv/config';
var corsOptions = {
origin: 'http://localhost:3000',
optionsSuccessStatus: 200
}
app.use(cors(corsOptions));
const port = process.env.PORT || 3000;
app.listen(port, () => {
console.log(`server runnig on port ${port}`);
});
This is babel.config.js code:
module.exports = {
presets: [
'@babel/preset-typescript',
[
'@babel/preset-env',
{
targets: {
node: 'current',
},
},
],
],
plugins: ['@babel/plugin-transform-runtime'],
};
This is package.json code:
{
"engines": {
"node": "18.4.0"
},
"scripts": {
"start": "babel-node -x .ts -- server.ts",
"start-old": "ts-node -r tsconfig-paths/register server.ts",
},
"prisma": {
"seed": "ts-node prisma/seed.ts"
},
"devDependencies": {
"prettier": "^2.6.2",
},
"dependencies": {
"@aws-sdk/client-cognito-identity": "^3.128.0",
"@aws-sdk/client-s3": "^3.128.0",
"@aws-sdk/credential-provider-cognito-identity": "^3.128.0",
"@aws-sdk/s3-request-presigner": "^3.130.0",
"@aws-sdk/types": "^3.127.0",
"@babel/cli": "^7.18.6",
"@babel/core": "^7.18.6",
"@babel/node": "^7.18.6",
"@babel/plugin-transform-runtime": "^7.18.6",
"@babel/preset-env": "^7.18.6",
"@babel/preset-typescript": "^7.18.6",
"@babel/runtime": "^7.18.6",
"@prisma/client": "^4.0.0",
"@types/babel__core": "^7.1.19",
"@types/express": "^4.17.13",
"@types/node": "^17.0.40",
"aws-cli": "^0.0.2",
"aws-sdk": "^2.1172.0",
"cors": "^2.8.5",
"dotenv": "^16.0.1",
"express": "^4.18.1",
"pino": "^8.1.0",
"prisma": "^4.0.0",
"ts-node": "^10.8.1",
"tsconfig-paths": "^4.0.0",
"typescript": "^4.7.4"
}
}
Does anyone know why this is happening, and what may be done to be possible to use import again?
Thanks a lot!