Skip to content

The return of "Unexpected end of JSON input" #584

@kf6kjg

Description

@kf6kjg

This is a Bug Report

Description

The command npx sls deploy --conceal with the following environment variables set failed with the titular error message. After some hacking and searching I think I found the source of the problem, and I'd send in a PR however I'm not yet sure the correct multi-platform solution.

My config:

  • Environment variables set via CLI:
    • NODE_ENV=staging
    • TS_NODE_PROJECT=webpack/tsconfig-for-webpack-config.json
  • Relevant blocks from my serverless.yml:
custom:
  webpack:
    webpackConfig: webpack/webpack.ts
    includeModules: true

package:
  individually: true

plugins:
  - serverless-dotenv-plugin
  - serverless-offline
  - serverless-offline-scheduler
  - serverless-webpack

And several other things in my config that I'm nearly 100% sure are not relevant to the problem at hand.

Similar or dependent issue(s):

Additional Data

$ npm -v
6.14.4
  • Serverless-Webpack Version you're using: "serverless-webpack": "^5.3.1"
  • Webpack version you're using: "webpack": "^4.29.0"
  • Serverless Framework Version you're using: "serverless": "^1.69.0"
  • Operating System: Kubuntu 18.04.3 (equivalent to Ubuntu 18.04.3 LTS)
  • Stack Trace (if available):
...
Serverless: Invoke webpack:package
  Syntax Error -------------------------------------------
 
  SyntaxError: Unexpected end of JSON input
      at JSON.parse (<anonymous>)
      at /home/ricky/data/dev_slidewave/serverless/node_modules/serverless-webpack/lib/packagers/npm.js:75:19
      at tryCatcher (/home/ricky/data/dev_slidewave/serverless/node_modules/bluebird/js/release/util.js:16:23)
      at Function.Promise.attempt.Promise.try (/home/ricky/data/dev_slidewave/serverless/node_modules/bluebird/js/release/method.js:39:29)
      at /home/ricky/data/dev_slidewave/serverless/node_modules/serverless-webpack/lib/packagers/npm.js:73:35
      at tryCatcher (/home/ricky/data/dev_slidewave/serverless/node_modules/bluebird/js/release/util.js:16:23)
      at Promise._settlePromiseFromHandler (/home/ricky/data/dev_slidewave/serverless/node_modules/bluebird/js/release/promise.js:547:31)
      at Promise._settlePromise (/home/ricky/data/dev_slidewave/serverless/node_modules/bluebird/js/release/promise.js:604:18)
      at Promise._settlePromise0 (/home/ricky/data/dev_slidewave/serverless/node_modules/bluebird/js/release/promise.js:649:10)
      at Promise._settlePromises (/home/ricky/data/dev_slidewave/serverless/node_modules/bluebird/js/release/promise.js:729:18)
      at _drainQueueStep (/home/ricky/data/dev_slidewave/serverless/node_modules/bluebird/js/release/async.js:93:12)
      at _drainQueue (/home/ricky/data/dev_slidewave/serverless/node_modules/bluebird/js/release/async.js:86:9)
      at Async._drainQueues (/home/ricky/data/dev_slidewave/serverless/node_modules/bluebird/js/release/async.js:102:5)
      at Immediate.Async.drainQueues [as _onImmediate] (/home/ricky/data/dev_slidewave/serverless/node_modules/bluebird/js/release/async.js:15:14)
      at processImmediate (internal/timers.js:456:21)
      at process.topLevelDomainCallback (domain.js:137:15)
 
  Your Environment Information ---------------------------
     Operating System:          linux
     Node Version:              13.14.0
     Framework Version:         1.69.0
     Plugin Version:            3.6.9
     SDK Version:               2.3.0
     Components Version:        2.30.4

As I said I did some digging and it seems that there's a buffering problem with the output of npm ls.
Manual execution of npm ls -prod -json -depth=1 > npmls.json results in npmls.txt.

So I utilized a concept from SO, though the unbuffer command isn't preinstalled on my system so I skipped the accepted answer's solution, and the stdbuf command didn't solve the problem. I modified npm.js::getProdDependencies as follows:

    const command = "script";
    const args = [
      '-q',
      '-c',
      `${/^win/.test(process.platform) ? 'npm.cmd' : 'npm'} ls -prod -json -depth=${depth || 1}`,
      '/dev/null'
    ];

Which, while having broad Linux support, won't work on BSD-based platforms or Windows. After making that change that error is resolved and I can proceed to the next problem to solve.

Thus this issue report: I found a solution, but it's not a good solution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions