I have a piece of code:
'use strict';
class ArticleModel {
constructor(options = {}) {
this.options = options
}
}
module.exports = ArticleModel
which results in the error Unexpected token =
- I don't believe Babel is parsing this. Which babel 6 plugin is needed to parse default parameters in a function?
Edit 1 - this is my .babelrc file
{
"presets": [
"es2015",
"stage-0"
]
}
Edit 2 - I am not running babel from the same directory as .babelrc
. I'm running babel from inside test/
where the structure looks like this:
/app
/test
/test/runner.js < -- this is what calls babel-core/register
.babelrc
Do I need to explicitly tell babel-core/register
where .babelrc
is? I assumed it rolled up a directory for it.
Edit 3 - changed babel/register
to babel-core/register
. Still get the same issue.
I have a piece of code:
'use strict';
class ArticleModel {
constructor(options = {}) {
this.options = options
}
}
module.exports = ArticleModel
which results in the error Unexpected token =
- I don't believe Babel is parsing this. Which babel 6 plugin is needed to parse default parameters in a function?
Edit 1 - this is my .babelrc file
{
"presets": [
"es2015",
"stage-0"
]
}
Edit 2 - I am not running babel from the same directory as .babelrc
. I'm running babel from inside test/
where the structure looks like this:
/app
/test
/test/runner.js < -- this is what calls babel-core/register
.babelrc
Do I need to explicitly tell babel-core/register
where .babelrc
is? I assumed it rolled up a directory for it.
Edit 3 - changed babel/register
to babel-core/register
. Still get the same issue.
- 'babel/register' doesn't exist anymore? should be 'babel-core/register' – Seneca Commented Nov 9, 2015 at 14:17
-
Tks @Seneca but I still get the same error even when changing it to
babel-core/register
. – Chris Abrams Commented Nov 9, 2015 at 14:24
2 Answers
Reset to default 5npm install babel-preset-es2015 --save-dev
Add the following line to your .babelrc file:
{
"presets": ["es2015"]
}
Did you try this?
How are you importing the module into the test? I had a similar problem when my tests started to break after upgrading from Babel 5 to 6. In my case it turned out that the problem was because the import has to referenced the default
property in the imported lib.
The initiator of this Babel issue gives a good example: https://github./babel/babel/issues/2679
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745654274a4638449.html
评论列表(0条)