admin管理员组文章数量:1026938
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
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
本文标签: javascriptBabel 6Enable default parameters for functionsStack Overflow
版权声明:本文标题:javascript - Babel 6 - Enable default parameters for functions - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745654273a2161503.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论