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.

Share Improve this question edited Nov 10, 2015 at 4:04 Guy 67.5k101 gold badges265 silver badges332 bronze badges asked Nov 9, 2015 at 13:55 Chris AbramsChris Abrams 42.6k20 gold badges54 silver badges57 bronze badges 2
  • '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
Add a ment  | 

2 Answers 2

Reset to default 5
npm 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.

Share Improve this question edited Nov 10, 2015 at 4:04 Guy 67.5k101 gold badges265 silver badges332 bronze badges asked Nov 9, 2015 at 13:55 Chris AbramsChris Abrams 42.6k20 gold badges54 silver badges57 bronze badges 2
  • '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
Add a ment  | 

2 Answers 2

Reset to default 5
npm 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