1

I have a Node.JS (version 8.6) based Google Home app that uses the Actions on Google Javascript client library. It has built and ran fine for several days now. I added a few packages to the project and all of a sudden I start getting the following fatal error in the Actions on Google Javascript client library, despite the fact the code in that library has not been touched:

/**
 * The Actions on Google client library.
 * https://developers.google.com/actions/
 */

'use strict';

const AssistantApp = require('./assistant-app');
^^^^^
SyntaxError: Use of const in strict mode.
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/home/roschler/Documents/GitHub/YourMD/google-assistant/morse-integration/routes/fulfillment.js:16:21)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)

I never got this error before. Below is my package.json file:

{
  "name": "test",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "start": "node ./bin/www"
  },
  "dependencies": {
    "aws-sdk": "^2.3.17",
    "actions-on-google": "^1.4.0",
    "archiver": "^1.3.0",
    "body-parser": "~1.13.3",
    "bluebird": "^3.4.0",
    "cookie-parser": "~1.3.5",
    "config": "^1.21.0",
    "debug": "~2.2.0",
    "express": "~4.13.1",
    "glob": "~7.0.3",
    "http-status-codes": "~1.0.6",
    "jade": "~1.11.0",
    "jsonfile": "~2.2.3",
    "marked": "^0.3.5",
    "morgan": "~1.6.1",
    "pg": "^6.1.4",
    "redis": "^2.6.1",
    "request": "^2.72.0",
    "scribe-js": "~2.0.4",
    "serve-favicon": "~2.3.0",
    "showdown": "^1.7.1",
    "simple-spinner": "0.0.5",
    "ssl-root-cas": "~1.2.2",
    "underscore": "^1.8.3"
  }
}

Does anyone know why this is happening and what I can do to fix it? I tried updating my Node.JS version as per the accepted answer the Stack Overflow post below regarding a similar error, but it did not help:

SyntaxError: Use of const in strict mode?

I still get the error.

UPDATE: I forgot that I also upgraded from Node 7.2 to 8.6. I believe now that's what is causing my issues. I'm in the process of doing a full purge of Node.js and then installing nvm so I can test versions.

Robert Oschler
  • 14,153
  • 18
  • 94
  • 227
  • 1
    What version of Node? – Mark Oct 13 '17 at 21:59
  • 1
    What are the lines just before the require()? – Prisoner Oct 13 '17 at 22:15
  • @Mark_M Version 8.6. – Robert Oschler Oct 13 '17 at 22:32
  • @Prisoner - I just added those to my post. Pretty much just 'use strict' and some comments before that. As I said, I haven't touched the code in that file. – Robert Oschler Oct 13 '17 at 22:32
  • All signs point to the fact that you aren't actually getting node v8.6 when you run your app and have some older version that is causing this. – jfriend00 Oct 14 '17 at 01:00
  • @jfriend00 I think it's the opposite. All my troubles started when I upgraded from 7.2 to 8.6. I'm going to do a complete purge and install nvm and then go back to an older version to see what happens. – Robert Oschler Oct 14 '17 at 01:02
  • I rather doubt that 8.x broke the use of `const`. Perhaps something went wrong with your upgrade process though. Probably also worth ruling out some other cause by creating a simple test file with nothing else in it, but this issue. – jfriend00 Oct 14 '17 at 01:12
  • 1
    For Actions on Google you have to use the LTS version of nodejs - which is 6.x – Wolfram Rittmeyer Oct 17 '17 at 09:19
  • 1
    @WolframRittmeyer Thanks. I ended up reverting to 6.11.1 since that is what Firebase uses and you're right, the problem went away when I did that. – Robert Oschler Oct 17 '17 at 17:07
  • 1
    @WolframRittmeyer please be more specific. Actions on Google is a platform that doesn't have any specific platform requirements. If you mean the AoG Node package has an Engine requirement please link to where that is specified. – abraham Oct 17 '17 at 19:36
  • @abraham Actually I got confused and mixed up Cloud Functions and it's implications for this lib. Cloud Functions (both variants) require node with LTS. The actions-on-google lib most likely not. At least all my tests run fine with the newest node version as well with the LTS version. When I got the same error it was on Cloud Functions. – Wolfram Rittmeyer Oct 18 '17 at 21:16

0 Answers0