Syntactic Fructose
Syntactic Fructose

Reputation: 20104

Babel unexpected token ':' during let clause

I have the following code segment:

  let baseUrl = '/';
  let url = req.originalUrl || '/';

  let config: ExpressEngineConfig = {
    directives: [ App ],

when I attempt to compile this file using babel, I get the error

SyntaxError: server.js: Unexpected token, expected ; (37:12)

The error points at the : character as the unexpected token. Am I missing something? Here's my .babelrc. Thanks for any help

{
    "presets": ["es2015"]
}

Upvotes: 0

Views: 488

Answers (1)

ssube
ssube

Reputation: 48287

You have a type annotation in let config: ExpressEngineConfig, which is not part of JS (es2015 or otherwise).

If you're using Flow type annotations, you'll need to enable the plugin as described in the Babel docs:

{
  "plugins": ["syntax-flow"]
}

If you're using Typescript, you'll need to compile that to JS before running Babel.

Upvotes: 5

Related Questions