Hapi: SyntaxError: Unexpected token =

Created on 29 Feb 2020  ·  7Comments  ·  Source: hapijs/hapi

Support plan

  • which support plan is this issue covered by? Community, Core, Plus, or Enterprise): Community
  • is this issue currently blocking your project? (yes/no): yes
  • is this issue affecting a production system? (yes/no): no

Context

  • node version: 12.14.1
  • module version: 19.1.1
  • environment (e.g. node, browser, native): node
  • used with (e.g. hapi application, another framework, standalone, ...): hapi application
  • any other relevant information: N/A

How can we help?

First of all, thank you @hueniverse, for such a wonderful tool!

I did run into a bit of a problem though. I am getting this error when I run my hapi application:

/home/vehmloewff/Code/auto-deploy/node_modules/@hapi/hapi/lib/core.js:51
    actives = new WeakMap();                                                   // Active requests being processed
            ^

SyntaxError: Unexpected token =
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:616:28)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/home/vehmloewff/Code/auto-deploy/node_modules/@hapi/hapi/lib/server.js:9:14)

The line that node is complaining about is this: lib/core.js:51

I did some research and couldn't find anything about this. Any guidance/help would be greatly appreciated.

support

Most helpful comment

I don't think you're actually using node 12, make sure of that.

All 7 comments

I don't think you're actually using node 12, make sure of that.

Maybe the node version logger broke, but I doubt that.

$ node -v
v12.14.1
$ npm start

> [email protected] start /home/vehmloewff/Code/auto-deploy
> sudo node dist/build.js

/home/vehmloewff/Code/auto-deploy/node_modules/@hapi/hapi/lib/core.js:51
    actives = new WeakMap();                                                   // Active requests being processed
            ^

SyntaxError: Unexpected token =

I'll take a guess and say you're using nvm or something like that. sudo loses context of that, you're getting your system's node version.

Oh. You are right. Thanks for the help!

I also ran into this issue... Why was engines removed from package.json? See https://github.com/hapijs/hapi/issues/3866. Version 19 requires Node 12 but this isn’t advertised in package.json or https://github.com/hapijs/hapi or https://www.npmjs.com/package/@hapi/hapi.

same issue here .. problem when running from npm script

$ node -v
v12.16.3

$ npm start

[email protected] serve /home/blue/Code/admin-api
node build/src/index.js

/home/blue/Code/admin-api/node_modules/@hapi/hapi/lib/core.js:51
actives = new WeakMap(); // Active requests being processed
^

SyntaxError: Unexpected token =
at new Script (vm.js:51:7)
at createScript (vm.js:138:10)
at Object.runInThisContext (vm.js:199:10)
at Module._compile (module.js:624:28)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
at Module.require (module.js:604:17)
at require (internal/module.js:11:18)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] serve: node build/src/index.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] serve script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /home/blue/.npm/_logs/2020-05-07T12_41_23_976Z-debug.log

but it works well when running from command shell
$ node build/src/index.js
ℹ Running enviroment dev
ℹ All plugins registered successfully.
✔ APIs registered sucessfully.

ℹ CORE API >>>
ℹ Server running at: http://localhost:3000

ℹ Docs address: http://localhost:3000/api/v1/docs

✔ Database is connected

removing node package resolves the problem
$ npm r node

same issue here .. problem when running from npm script

$ node -v
v12.16.3

$ npm start

[email protected] serve /home/blue/Code/admin-api
node build/src/index.js

/home/blue/Code/admin-api/node_modules/@hapi/hapi/lib/core.js:51
actives = new WeakMap(); // Active requests being processed
^

SyntaxError: Unexpected token =
at new Script (vm.js:51:7)
at createScript (vm.js:138:10)
at Object.runInThisContext (vm.js:199:10)
at Module._compile (module.js:624:28)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
at Module.require (module.js:604:17)
at require (internal/module.js:11:18)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] serve: node build/src/index.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] serve script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /home/blue/.npm/_logs/2020-05-07T12_41_23_976Z-debug.log

but it works well when running from command shell
$ node build/src/index.js
Running enviroment dev
All plugins registered successfully.
APIs registered sucessfully.

CORE API >>>

Server running at: http://localhost:3000
Docs address: http://localhost:3000/api/v1/docs
Database is connected

Was this page helpful?
0 / 5 - 0 ratings

Related issues

taoeffect picture taoeffect  ·  3Comments

AdriVanHoudt picture AdriVanHoudt  ·  5Comments

leore picture leore  ·  4Comments

mahnunchik picture mahnunchik  ·  4Comments

RohovDmytro picture RohovDmytro  ·  4Comments