Unexpected token in JSON when running serverless deploy

I am running into this error while trying to deploy an application to one of my environments. Enabling SLS_DEBUG=true gives me the following stack trace

▶ sls deploy -s dev
 
  Syntax Error -------------------------------------------
 
     Unexpected string in JSON at position 156
 
     For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.
 
  Stack Trace --------------------------------------------
 
SyntaxError: Unexpected string in JSON at position 156
SyntaxError: Unexpected string in JSON at position 156
    at JSON.parse (<anonymous>)
    at readFileSync (/usr/lib/node_modules/serverless/lib/utils/fs/readFileSync.js:14:21)
    at Utils.readFileSync (/usr/lib/node_modules/serverless/lib/classes/Utils.js:75:12)
    at Variables.getValueFromFile (/usr/lib/node_modules/serverless/lib/classes/Variables.js:263:47)
    at Variables.getValueFromSource (/usr/lib/node_modules/serverless/lib/classes/Variables.js:176:19)
    at Promise (/usr/lib/node_modules/serverless/lib/classes/Variables.js:98:23)
    at property.match.forEach (/usr/lib/node_modules/serverless/lib/classes/Variables.js:93:39)
    at Array.forEach (native)
    at Variables.populateProperty (/usr/lib/node_modules/serverless/lib/classes/Variables.js:88:43)
    at BbPromise.all.then (/usr/lib/node_modules/serverless/lib/classes/Variables.js:120:23)
    at tryCatcher (/usr/lib/node_modules/serverless/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/usr/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:512:31)
    at Promise._settlePromise (/usr/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromise0 (/usr/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:614:10)
    at Promise._settlePromises (/usr/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:693:18)
    at Promise._fulfill (/usr/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:638:18)
From previous event:
    at Variables.populateProperty (/usr/lib/node_modules/serverless/lib/classes/Variables.js:118:24)
    at BbPromise.all.then (/usr/lib/node_modules/serverless/lib/classes/Variables.js:120:23)
From previous event:
    at Variables.populateProperty (/usr/lib/node_modules/serverless/lib/classes/Variables.js:118:49)
    at Promise (/usr/lib/node_modules/serverless/lib/classes/Variables.js:67:12)
    at deepMapValues (/usr/lib/node_modules/serverless/lib/classes/Variables.js:66:40)
    at deepMapValues (/usr/lib/node_modules/serverless/lib/classes/Variables.js:61:14)
    at deepMapValuesIteratee (/usr/lib/node_modules/serverless/lib/classes/Variables.js:51:25)
    at /usr/lib/node_modules/serverless/node_modules/lodash/lodash.js:13379:38
    at /usr/lib/node_modules/serverless/node_modules/lodash/lodash.js:4944:15
    at baseForOwn (/usr/lib/node_modules/serverless/node_modules/lodash/lodash.js:3001:24)
    at Function.mapValues (/usr/lib/node_modules/serverless/node_modules/lodash/lodash.js:13378:7)
    at deepMapValues (/usr/lib/node_modules/serverless/lib/classes/Variables.js:59:39)
    at deepMapValuesIteratee (/usr/lib/node_modules/serverless/lib/classes/Variables.js:51:25)
    at /usr/lib/node_modules/serverless/node_modules/lodash/lodash.js:13379:38
    at /usr/lib/node_modules/serverless/node_modules/lodash/lodash.js:4944:15
    at baseForOwn (/usr/lib/node_modules/serverless/node_modules/lodash/lodash.js:3001:24)
    at Function.mapValues (/usr/lib/node_modules/serverless/node_modules/lodash/lodash.js:13378:7)
    at deepMapValues (/usr/lib/node_modules/serverless/lib/classes/Variables.js:59:39)
    at Variables.populateObject (/usr/lib/node_modules/serverless/lib/classes/Variables.js:64:5)
    at Variables.populateService (/usr/lib/node_modules/serverless/lib/classes/Variables.js:40:17)
    at Serverless.run (/usr/lib/node_modules/serverless/lib/Serverless.js:87:27

The stack trace isn’t clear about which JSON file is causing the error. FWIW, I have the following files in the .serverless directory

  • cloudformation-template-create-stack.json
  • cloudformation-template-update-stack.json
    I validated both of these JSON files and found them to be free of errors.

Can someone point me in the right direction to debug this further?

Environment info

     OS:                 linux
     Node Version:       7.10.0
     Serverless Version: 1.14.0

Are you reading variables from external files? That stack trace looks like it’s trying to read variables from a JSON file and not getting JSON.

Thanks. It was indeed an error in one of my config files.