Next.js: JSX unexpected token

Created on 14 Apr 2017  路  5Comments  路  Source: vercel/next.js

Hi, I'm using the latest versions and has encountered an error on a simple skeleton:

Module build failed: SyntaxError: Unexpected token (27:6)

  25 |   render() {
  26 |     return (
> 27 |       <div>
     |       ^
  28 |         {JSON.stringify(this.props)}
  29 |       </div>
  30 |     );

Is there any special steps required for JSX?

Also, I'm getting transpiling error:

ReferenceError: regeneratorRuntime is not defined

Most helpful comment

Have you customized the Babel configuration? Check in the console when you run next if are getting a message about a custom config, maybe you have a .babelrc in a parent directory and is being applied.

JSX works out of the box, that is the most usual reason I have seen for not working.

All 5 comments

Have you customized the Babel configuration? Check in the console when you run next if are getting a message about a custom config, maybe you have a .babelrc in a parent directory and is being applied.

JSX works out of the box, that is the most usual reason I have seen for not working.

@sergiodxa you're right! Had a package json somewhere above. Thanks :)

@khankuan it looks like i'm running into a similar issue where I have a parent folder with a babel configuration. curious what your fix was for this issue?

I removed the package.json file and it worked.

In your current folder add a new .babelrc file with:

{ "presets": "next/babel", "env": { "test": { "presets": [ "env", "next/babel" ] } } }

Was this page helpful?
0 / 5 - 0 ratings