question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

4.1 Unexpected token function

See original GitHub issue

bodyparser(4.1) in Koa(2.2.0)

just use like app.use(bodyParser());

error showed as below:

/some/path/node_modules/koa-bodyparser/index.js:69
  return async function bodyParser(ctx, next) {
               ^^^^^^^^
SyntaxError: Unexpected token function
    at Object.exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:513:28)
    at Module._extensions..js (module.js:550:10)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/zhangyan/Documents/Zalaxy/node_modules/babel-register/lib/node.js:152:7)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)
    at Module.require (module.js:468:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/some/path/server/app.js:4:20)

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

12reactions
dead-horsecommented, Mar 16, 2017

ensure your node version is >=7.6.0

3reactions
struCodercommented, May 7, 2017

this is okay

const babelrc = {
  "ignore": /node_modules\/(?!(koa-bodyparser)\/).*/,
  "presets": ["node6"],
  "plugins": [
    "transform-class-properties",
    "transform-async-to-generator"
  ]
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

SyntaxError: Unexpected token - JavaScript - MDN Web Docs
The JavaScript exceptions "unexpected token" occur when a specific language construct was expected, but something else was provided.
Read more >
SyntaxError: Unexpected token function - Async Await Nodejs
You'll need to transpile your code (e.g. using Babel) to a version of JS that Node understands if you are using an older...
Read more >
Unexpected token - Routing - Ghost Forum
I want to make autodeploy themes from github. I did it sort of like everything according to the instructions: Deploy Ghost Theme
Read more >
T189451 Jenkins fails to merge a patch with "Unexpected ...
Jenkins fails to merge a patch with "Unexpected token function". Closed, ResolvedPublic. Actions.
Read more >
Node.js v19.3.0 Documentation
doesNotThrow(fn[, error][, message]); assert.equal(actual, expected[, message]) ... Functions to convert from C types to Node-API ... parseArgs tokens.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found