Reputation: 378
I have a project created using babel-preset-react-app
. I want to analyze some of my files at build/precommit by running a script with @babel/node
. Unfortunately I'm getting the following error:
trpgb21@development:~/develop/ts-demo-new$ DEBUG=* NODE_ENV=production npx babel-node --extensions '.ts,.tsx'
> var test = require('./src')
babel:config:loading:files:configuration Found configuration '/home/trpgb21/develop/ts-demo-new/package.json' from '/home/trpgb21/develop/ts-demo-new'. +0ms
babel:config:loading:files:plugins Loaded preset 'react-app' from '/home/trpgb21/develop/ts-demo-new'. +0ms
babel program.body[0] VariableDeclaration: enter +0ms
babel program.body[0] VariableDeclaration: Recursing into... +1ms
babel program.body[0].declarations[0] VariableDeclarator: enter +0ms
babel program.body[0].declarations[0] VariableDeclarator: Recursing into... +0ms
babel program.body[0].declarations[0].id Identifier: enter +0ms
babel program.body[0].declarations[0].id Identifier: Recursing into... +0ms
babel program.body[0].declarations[0].id Identifier: exit +0ms
babel program.body[0].declarations[0].init CallExpression: enter +0ms
babel program.body[0].declarations[0].init CallExpression: Recursing into... +1ms
babel program.body[0].declarations[0].init.callee Identifier: enter +0ms
babel program.body[0].declarations[0].init.callee Identifier: Recursing into... +0ms
babel program.body[0].declarations[0].init.callee Identifier: exit +0ms
babel program.body[0].declarations[0].init.arguments[0] StringLiteral: enter +0ms
babel program.body[0].declarations[0].init.arguments[0] StringLiteral: Recursing into... +0ms
babel program.body[0].declarations[0].init.arguments[0] StringLiteral: exit +0ms
babel program.body[0].declarations[0].init CallExpression: exit +0ms
babel program.body[0].declarations[0] VariableDeclarator: exit +0ms
babel program.body[0] VariableDeclaration: exit +0ms
babel program Program: enter +2ms
babel program.body[2] ExpressionStatement: Inserted. +1ms
babel program.body[0] VariableDeclaration: enter +0ms
babel program.body[0] VariableDeclaration: Recursing into... +1ms
babel program.body[0].declarations[0] VariableDeclarator: enter +0ms
babel program.body[0].declarations[0] VariableDeclarator: Recursing into... +0ms
babel program.body[0].declarations[0].init CallExpression: enter +0ms
babel program.body[0].declarations[0].init CallExpression: Recursing into... +0ms
babel program.body[0].declarations[0].init CallExpression: exit +0ms
babel program.body[0].declarations[0] VariableDeclarator: exit +0ms
babel program.body[0] VariableDeclaration: exit +0ms
babel program.body[1] ExpressionStatement: enter +0ms
babel program.body[1] ExpressionStatement: Recursing into... +0ms
babel program.body[1] ExpressionStatement: exit +0ms
babel program.body[0] VariableDeclaration: enter +1ms
babel program.body[0] VariableDeclaration: Recursing into... +0ms
babel program.body[0].declarations[0] VariableDeclarator: enter +0ms
babel program.body[0].declarations[0] VariableDeclarator: Recursing into... +0ms
babel program.body[0].declarations[0].init CallExpression: enter +0ms
babel program.body[0].declarations[0].init CallExpression: Recursing into... +0ms
babel program.body[0].declarations[0].init CallExpression: exit +0ms
babel program.body[0].declarations[0] VariableDeclarator: exit +0ms
babel program.body[0] VariableDeclaration: exit +0ms
babel program.body[1] ExpressionStatement: enter +0ms
babel program.body[1] ExpressionStatement: Recursing into... +0ms
babel program.body[1] ExpressionStatement: exit +1ms
babel program.body[0] VariableDeclaration: enter +0ms
babel program.body[0] VariableDeclaration: Recursing into... +0ms
babel program.body[0].declarations[0] VariableDeclarator: enter +0ms
babel program.body[0].declarations[0] VariableDeclarator: Recursing into... +0ms
babel program.body[0].declarations[0].id Identifier: enter +0ms
babel program.body[0].declarations[0].id Identifier: Recursing into... +0ms
babel program.body[0].declarations[0].id Identifier: exit +0ms
babel program.body[0].declarations[0].init CallExpression: enter +0ms
babel program.body[0].declarations[0].init CallExpression: Recursing into... +0ms
babel program.body[0].declarations[0].init.callee Identifier: enter +0ms
babel program.body[0].declarations[0].init.callee Identifier: Recursing into... +0ms
babel program.body[0].declarations[0].init.callee Identifier: exit +0ms
babel program.body[0].declarations[0].init.arguments[0] StringLiteral: enter +0ms
babel program.body[0].declarations[0].init.arguments[0] StringLiteral: Recursing into... +0ms
babel program.body[0].declarations[0].init.arguments[0] StringLiteral: exit +0ms
babel program.body[0].declarations[0].init CallExpression: exit +0ms
babel program.body[0].declarations[0] VariableDeclarator: exit +0ms
babel program.body[0] VariableDeclaration: exit +0ms
babel program.body[1] ExpressionStatement: enter +0ms
babel program.body[1] ExpressionStatement: Recursing into... +0ms
babel program.body[1].expression Identifier: enter +0ms
babel program.body[1].expression Identifier: Recursing into... +1ms
babel program.body[1].expression Identifier: exit +0ms
babel program.body[1] ExpressionStatement: exit +0ms
babel program.body[0] VariableDeclaration: enter +0ms
babel program.body[0] VariableDeclaration: Recursing into... +0ms
babel program.body[0].declarations[0] VariableDeclarator: enter +0ms
babel program.body[0].declarations[0] VariableDeclarator: Recursing into... +0ms
babel program.body[0].declarations[0].init CallExpression: enter +0ms
babel program.body[0].declarations[0].init CallExpression: Recursing into... +0ms
babel program.body[0].declarations[0].init CallExpression: exit +0ms
babel program.body[0].declarations[0] VariableDeclarator: exit +0ms
babel program.body[0] VariableDeclaration: exit +0ms
babel program.body[1] ExpressionStatement: enter +0ms
babel program.body[1] ExpressionStatement: Recursing into... +0ms
babel program.body[1] ExpressionStatement: exit +0ms
babel program.body[0] VariableDeclaration: enter +1ms
babel program.body[0] VariableDeclaration: Recursing into... +0ms
babel program.body[0].declarations[0] VariableDeclarator: enter +0ms
babel program.body[0].declarations[0] VariableDeclarator: Recursing into... +0ms
babel program.body[0].declarations[0].init CallExpression: enter +0ms
babel program.body[0].declarations[0].init CallExpression: Recursing into... +0ms
babel program.body[0].declarations[0].init CallExpression: exit +0ms
babel program.body[0].declarations[0] VariableDeclarator: exit +0ms
babel program.body[0] VariableDeclaration: exit +0ms
babel program.body[1] ExpressionStatement: enter +0ms
babel program.body[1] ExpressionStatement: Recursing into... +0ms
babel program.body[1] ExpressionStatement: exit +0ms
babel program Program: Recursing into... +0ms
babel program.body[0] VariableDeclaration: enter +0ms
babel program.body[0] VariableDeclaration: Recursing into... +1ms
babel program.body[0].declarations[0] VariableDeclarator: enter +0ms
babel program.body[0].declarations[0] VariableDeclarator: Recursing into... +0ms
babel program.body[0].declarations[0].id Identifier: enter +0ms
babel program.body[0].declarations[0].id Identifier: Recursing into... +0ms
babel program.body[0].declarations[0].id Identifier: exit +0ms
babel program.body[0].declarations[0].init CallExpression: enter +0ms
babel program.body[0].declarations[0].init CallExpression: Recursing into... +1ms
babel program.body[0].declarations[0].init.callee Identifier: enter +0ms
babel program.body[0].declarations[0].init.callee Identifier: Recursing into... +0ms
babel program.body[0].declarations[0].init.callee Identifier: exit +0ms
babel program.body[0].declarations[0].init.arguments[0] StringLiteral: enter +4ms
babel program.body[0].declarations[0].init.arguments[0] StringLiteral: Recursing into... +1ms
babel program.body[0].declarations[0].init.arguments[0] StringLiteral: exit +0ms
babel program.body[0].declarations[0].init CallExpression: exit +0ms
babel program.body[0].declarations[0] VariableDeclarator: exit +0ms
babel program.body[0] VariableDeclaration: exit +0ms
babel program.body[1] ExpressionStatement: enter +0ms
babel program.body[1] ExpressionStatement: Recursing into... +0ms
babel program.body[1].expression Identifier: enter +0ms
babel program.body[1].expression Identifier: Recursing into... +0ms
babel program.body[1].expression Identifier: exit +0ms
babel program.body[1] ExpressionStatement: exit +0ms
babel program Program: exit +0ms
babel program.body[1] ExpressionStatement: enter +0ms
babel program.body[1] ExpressionStatement: Recursing into... +1ms
babel program.body[1].expression Identifier: enter +0ms
babel program.body[1].expression Identifier: Recursing into... +0ms
babel program.body[1].expression Identifier: exit +0ms
babel program.body[1] ExpressionStatement: exit +0ms
babel:config:loading:files:configuration Found configuration '/home/trpgb21/develop/ts-demo-new/package.json' from '/home/trpgb21/develop/ts-demo-new/src'. +305ms
Thrown:
/home/trpgb21/develop/ts-demo-new/src/index.tsx:1
import * as React from "react";
^
SyntaxError: Unexpected token *
Why isn't babel transforming the code using the preset???
Here is my package.json
babel block for reference:
"babel": {
"presets": [
"react-app"
]
},
Upvotes: 0
Views: 547
Reputation: 564
Passing "debug": true
to @babel/preset-env
resolved this for me, in case anyone else is running into a recursive program.body loop with babel:
{
"presets": [
[
"@babel/preset-env",
{
"loose": true,
"modules": false,
"debug": true
}
]
],
"env": {
"commonjs": {
"presets": [
[
"@babel/preset-env",
{
"loose": true,
"modules": "commonjs"
}
]
]
},
"test": {
"presets": [
[
"@babel/preset-env",
{
"loose": true
}
]
]
}
}
}
Upvotes: 0