Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kf6kjg opened this issue Apr 30, 2020 · 2 comments
Open

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

kf6kjg opened this issue Apr 30, 2020 · 2 comments

Comments

@kf6kjg
Copy link

kf6kjg commented Apr 30, 2020

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.

@kf6kjg
Copy link
Author

kf6kjg commented Apr 30, 2020

Funny thing was that just yesterday I spent the whole day trying to figure out why a spawn call in my own code wasn't getting anything on stdin or sending anything on stdout, wound up anbanding spawn for an alternative I was able to get away with: the command I was calling was just another TypeScript module, so I refactored its core into a library module and called that via import instead of spawning a whole process. But I digress.

@ernesto-castelan-movile

I was having this error using node 12.19.0 installed as a snap
I switched to this installation and the problem is resolved
https://github.com/nodesource/distributions/blob/master/README.md#deb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants