babel: babel-register does not seem to load plugins
Bug Report
Current Behavior
I am running mocha (v5.2.0) with @babel/register
and it does not seem to strip flow types which makes me think that it does not read .babelrc
.
babel src/ --copy-files --out-dir build
works fine on the other side.
yarn test
yarn run v1.9.4
$ mocha -R spec --compilers js:@babel/register --require "test/setup.js" "test/**/*.spec.js"
~/project/app/node_modules/@babel/register/node_modules/@babel/core/lib/transformation/normalize-file.js:174
throw err;
^
SyntaxError:~/project/app/packages/components/test/AccountInput.spec.js: Unexpected token, expected "," (13:28)
11 | };
12 |
> 13 | const render = (mergeProps: $Shape<React.ElementProps<typeof AccountInput>>) => {
| ^
14 | const defaultProps: React.ElementProps<typeof AccountInput> = {
15 | value: '',
16 | onEnter: null,
at _class.raise (~/project/app/node_modules/babylon/lib/index.js:776:15)
at _class.unexpected (~/project/app/node_modules/babylon/lib/index.js:2079:16)
at _class.expect (~/project/app/node_modules/babylon/lib/index.js:2067:28)
at _class.parseParenAndDistinguishExpression (~/project/app/node_modules/babylon/lib/index.js:3283:14)
at _class.parseExprAtom (~/project/app/node_modules/babylon/lib/index.js:3113:21)
at _class.parseExprAtom (~/project/app/node_modules/babylon/lib/index.js:8185:52)
at _class.parseExprSubscripts (~/project/app/node_modules/babylon/lib/index.js:2757:21)
at _class.parseMaybeUnary (~/project/app/node_modules/babylon/lib/index.js:2736:21)
at _class.parseExprOps (~/project/app/node_modules/babylon/lib/index.js:2643:21)
at _class.parseMaybeConditional (~/project/app/node_modules/babylon/lib/index.js:2615:21)
at _class.parseMaybeAssign (~/project/app/node_modules/babylon/lib/index.js:2562:21)
at _class.parseVar (~/project/app/node_modules/babylon/lib/index.js:4582:26)
at _class.parseVarStatement (~/project/app/node_modules/babylon/lib/index.js:4412:10)
at _class.parseStatementContent (~/project/app/node_modules/babylon/lib/index.js:4012:21)
at _class.parseStatement (~/project/app/node_modules/babylon/lib/index.js:3962:17)
at _class.parseBlockOrModuleBlockBody (~/project/app/node_modules/babylon/lib/index.js:4513:23)
at _class.parseBlockBody (~/project/app/node_modules/babylon/lib/index.js:4500:10)
at _class.parseBlock (~/project/app/node_modules/babylon/lib/index.js:4489:10)
at _class.parseFunctionBody (~/project/app/node_modules/babylon/lib/index.js:3754:24)
at _class.parseArrowExpression (~/project/app/node_modules/babylon/lib/index.js:3706:10)
at _class.parseParenAndDistinguishExpression (~/project/app/node_modules/babylon/lib/index.js:3322:12)
at _class.parseExprAtom (~/project/app/node_modules/babylon/lib/index.js:3113:21)
at _class.parseExprAtom (~/project/app/node_modules/babylon/lib/index.js:8185:52)
at _class.parseExprSubscripts (~/project/app/node_modules/babylon/lib/index.js:2757:21)
at _class.parseMaybeUnary (~/project/app/node_modules/babylon/lib/index.js:2736:21)
at _class.parseExprOps (~/project/app/node_modules/babylon/lib/index.js:2643:21)
at _class.parseMaybeConditional (~/project/app/node_modules/babylon/lib/index.js:2615:21)
at _class.parseMaybeAssign (~/project/app/node_modules/babylon/lib/index.js:2562:21)
at _class.parseExprListItem (~/project/app/node_modules/babylon/lib/index.js:3824:18)
at _class.parseCallExpressionArguments (~/project/app/node_modules/babylon/lib/index.js:2953:22)
at _class.parseSubscript (~/project/app/node_modules/babylon/lib/index.js:2862:32)
at _class.parseSubscripts (~/project/app/node_modules/babylon/lib/index.js:2777:19)
at _class.parseExprSubscripts (~/project/app/node_modules/babylon/lib/index.js:2767:17)
at _class.parseMaybeUnary (~/project/app/node_modules/babylon/lib/index.js:2736:21)
at _class.parseExprOps (~/project/app/node_modules/babylon/lib/index.js:2643:21)
at _class.parseMaybeConditional (~/project/app/node_modules/babylon/lib/index.js:2615:21)
at _class.parseMaybeAssign (~/project/app/node_modules/babylon/lib/index.js:2562:21)
at _class.parseExpression (~/project/app/node_modules/babylon/lib/index.js:2515:21)
at _class.parseStatementContent (~/project/app/node_modules/babylon/lib/index.js:4076:21)
at _class.parseStatement (~/project/app/node_modules/babylon/lib/index.js:3962:17)
at _class.parseBlockOrModuleBlockBody (~/project/app/node_modules/babylon/lib/index.js:4513:23)
at _class.parseBlockBody (~/project/app/node_modules/babylon/lib/index.js:4500:10)
at _class.parseTopLevel (~/project/app/node_modules/babylon/lib/index.js:3938:10)
at _class.parse (~/project/app/node_modules/babylon/lib/index.js:5304:17)
at parse (~/project/app/node_modules/babylon/lib/index.js:10095:38)
at parser (~/project/app/node_modules/@babel/register/node_modules/@babel/core/lib/transformation/normalize-file.js:139:35)
at normalizeFile (~/project/app/node_modules/@babel/register/node_modules/@babel/core/lib/transformation/normalize-file.js:87:11)
at runSync (~/project/app/node_modules/@babel/register/node_modules/@babel/core/lib/transformation/index.js:44:43)
at transformSync (~/project/app/node_modules/@babel/register/node_modules/@babel/core/lib/transform-sync.js:17:38)
at Object.transform (~/project/app/node_modules/@babel/register/node_modules/@babel/core/lib/transform.js:22:65)
at compile (~/project/app/node_modules/@babel/register/lib/node.js:73:20)
at compileHook (~/project/app/node_modules/@babel/register/lib/node.js:102:12)
at Module._compile (~/project/app/node_modules/pirates/lib/index.js:86:27)
at Module._extensions..js (module.js:663:10)
at Object.newLoader [as .js] (~/project/app/node_modules/pirates/lib/index.js:96:7)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at ~/project/app/node_modules/mocha/lib/mocha.js:250:27
at Array.forEach (<anonymous>)
at Mocha.loadFiles (~/project/app/node_modules/mocha/lib/mocha.js:247:14)
at Mocha.run (~/project/app/node_modules/mocha/lib/mocha.js:576:10)
at Object.<anonymous> (~/project/app/node_modules/mocha/bin/_mocha:637:18)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:191:16)
at bootstrap_node.js:612:3
error Command failed with exit code 1.
This may be related to https://github.com/babel/babel/issues/7701 but I was trying to run mocha directly without yarn workspaces and it has the same effect.
The weird thing, running with DEBUG=*
shows that babel finds the right config:
babel:config:loading:files:configuration Found configuration '~/project/app/packages/components/.babelrc' from '~/project/app/packages/components/test'. +1s
Expected behavior/code Should run tests.
Babel Configuration (.babelrc, package.json, cli command)
{
"presets": [
["@babel/preset-env", {
"targets": {
"node": "8.9"
}
}],
"@babel/preset-react",
"@babel/preset-flow"
],
"plugins": [
"@babel/plugin-proposal-class-properties",
"@babel/plugin-proposal-object-rest-spread"
]
}
Environment
- Babel version(s): 7.0.0-rc.1
- Node/npm version: yarn 1.9.4, node v8.11.2
- OS: macOS
- Monorepo: yes
- How you are using Babel: CLI
Possible Solution Not sure
Additional context/Screenshots None
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 17 (8 by maintainers)
@pvdlg
Not presently.
Assuming I understand you right, we have #7961 to track the possibility, but it’s not clear that it’s worth doing since we’re then mixing two currently-independent config formats.
I respect that, but at the end of the day it is what it is now. The only way to keep it as one format would have been to drop the file-relative resolution entirely, and then people would be just as frustrated, if not more so.
Is there a way to declare the
babel
config inpackage.json
as project-wide? Or is the only way is to have ababel.config.js
? I would prefer to use the config inpackage.json
rather than adding yet another config file at the root of my project…Was it discussed to identify project-wide config based on a property in the file (like
global
) or another mean, rather than the filename containing the config?Even if it’s clearly documented it’s quite unintuitive to have
babel.config.js
behaving differently than.babelrc
andpackage.json#babel
… For most tools out there arc
file, an entry inpackage.json
, arc.json
file, arc.yml
and a.config.js
are strictly equivalent.