serverless-webpack: Google and Firebase - Unexpected end of JSON input

This is a (Bug Report / Feature Proposal)

Bug

Description

For bug reports:

  • What went wrong?
⟩ serverless deploy

{}
Serverless: Bundling with Webpack...
Time: 637ms
   Asset     Size  Chunks             Chunk Names
index.js  4.32 kB       0  [emitted]  main
   [0] ./handler.js 1.57 kB {0} [built]
   [1] external "firebase-admin" 42 bytes {0} [not cacheable]
   [2] external "firebase-functions" 42 bytes {0} [not cacheable]

  Syntax Error -------------------------------------------

  Unexpected end of JSON input

     For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.

  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Forums:        forum.serverless.com
     Chat:          gitter.im/serverless/serverless

  Your Environment Information -----------------------------
     OS:                     darwin
     Node Version:           9.3.0
     Serverless Version:     1.25.0


  • What did you expect should have happened?

Deployed correctly

  • What was the config you used?
service: wrud

provider:
  name: google
  runtime: nodejs
  project: XXXX
  credentials: ~/.gcloud/XXXX.json

plugins:
  - serverless-google-cloudfunctions
  - serverless-webpack

custom:
  webpackIncludeModules:
    packagePath: './package.json'    

# needs more granular excluding in production as only the serverless provider npm
# package should be excluded (and not the whole node_modules directory)
package:
  exclude:
    - node_modules/**
    - .gitignore
    - .git/**

functions:
  hello:
    handler: helloWorld
    events:
      - http: path
  • What stacktrace or error message from your provider did you see?
  Stack Trace --------------------------------------------

SyntaxError: Unexpected end of JSON input
SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at BbPromise.try (/Users/work1/Projects/wrud/wrud/node_modules/serverless-webpack/lib/packExternalModules.js:236:47)
    at tryCatcher (/Users/work1/Projects/wrud/wrud/node_modules/bluebird/js/release/util.js:16:23)
    at Function.Promise.attempt.Promise.try (/Users/work1/Projects/wrud/wrud/node_modules/bluebird/js/release/method.js:39:29)
    at BbPromise.fromCallback.then.depJson (/Users/work1/Projects/wrud/wrud/node_modules/serverless-webpack/lib/packExternalModules.js:236:35)
    at tryCatcher (/Users/work1/Projects/wrud/wrud/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/Users/work1/Projects/wrud/wrud/node_modules/bluebird/js/release/promise.js:512:31)
    at Promise._settlePromise (/Users/work1/Projects/wrud/wrud/node_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromise0 (/Users/work1/Projects/wrud/wrud/node_modules/bluebird/js/release/promise.js:614:10)
    at Promise._settlePromises (/Users/work1/Projects/wrud/wrud/node_modules/bluebird/js/release/promise.js:693:18)
    at Promise._fulfill (/Users/work1/Projects/wrud/wrud/node_modules/bluebird/js/release/promise.js:638:18)
    at /Users/work1/Projects/wrud/wrud/node_modules/bluebird/js/release/nodeback.js:42:21
    at childProcess.exec (/Users/work1/Projects/wrud/wrud/node_modules/serverless-webpack/lib/packExternalModules.js:233:16)
    at ChildProcess.exithandler (child_process.js:279:5)
    at ChildProcess.emit (events.js:159:13)
    at maybeClose (internal/child_process.js:943:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:220:5)
From previous event:
    at PluginManager.invoke (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:368:22)
    at PluginManager.spawn (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:386:17)
    at ServerlessWebpack.BbPromise.bind.then.then.then (/Users/work1/Projects/wrud/wrud/node_modules/serverless-webpack/index.js:90:51)
    at runCallback (timers.js:773:18)
    at tryOnImmediate (timers.js:734:5)
    at processImmediate [as _immediateCallback] (timers.js:711:5)

Additional Data

package.json

{
  "name": "google-nodejs",
  "version": "0.1.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "serverless.com",
  "license": "MIT",
  "dependencies": {
    "babel-runtime": "^6.26.0",
    "firebase-admin": "^5.8.0",
    "firebase-functions": "^0.8.0",
    "jsonschema": "^1.2.2",
    "serverless-google-cloudfunctions": "^1.1.1"
  },
  "devDependencies": {
    "babel-core": "^6.26.0",
    "babel-loader": "^7.1.2",
    "babel-plugin-transform-runtime": "^6.23.0",
    "babel-preset-env": "^1.6.1",
    "babel-preset-stage-3": "^6.24.1",
    "eslint": "^4.15.0",
    "eslint-config-standard": "^11.0.0-beta.0",
    "eslint-plugin-import": "^2.8.0",
    "eslint-plugin-node": "^5.2.1",
    "eslint-plugin-promise": "^3.6.0",
    "eslint-plugin-standard": "^3.0.1",
    "serverless-webpack": "^4.2.0",
    "webpack": "^3.10.0",
    "webpack-node-externals": "^1.6.0"
  }
}

  • Serverless-Webpack Version you’re using: 4.2.0
  • Webpack version you’re using: 3.10.0
  • Serverless Framework Version you’re using: 1.25.0
  • Operating System: OSX 10.13.2 (17C88) High Sierra
  • Stack Trace (if available):

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 21 (10 by maintainers)

Commits related to this issue

Most upvoted comments

Looks like this is caused by using yarn. By deleting node_modules and then using npm, it works fine.

@alopes Yarn support is available in master now and will be part of the next release. Please give it a try and check if it now correctly handles yarn.lock and works with yarn as expected. The README in master contains the exact steps on how to configure it - and adjust the webpack plugin configuration in serverless.yml properly to the new format.

Hi @alopes . Thanks for the information and verification.

I think, having #286 done would make these cases very rare, as the plugin can then be configured to the packager that the user normally uses in his environment.

Hey, I believe I might be having the same issue. Works fine running locally with $sls offline start but once I try to deploy it I get that same error. Any ideas on how to tackle this issue? Thanks

➜  SLS_DEBUG=* serverless deploy
Serverless: Load command run
Serverless: Load command config
Serverless: Load command config:credentials
Serverless: Load command create
Serverless: Load command install
Serverless: Load command package
Serverless: Load command deploy
Serverless: Load command deploy:function
Serverless: Load command deploy:list
Serverless: Load command deploy:list:functions
Serverless: Load command invoke
Serverless: Load command invoke:local
Serverless: Load command info
Serverless: Load command logs
Serverless: Load command login
Serverless: Load command logout
Serverless: Load command metrics
Serverless: Load command print
Serverless: Load command remove
Serverless: Load command rollback
Serverless: Load command rollback:function
Serverless: Load command slstats
Serverless: Load command plugin
Serverless: Load command plugin
Serverless: Load command plugin:install
Serverless: Load command plugin
Serverless: Load command plugin:uninstall
Serverless: Load command plugin
Serverless: Load command plugin:list
Serverless: Load command plugin
Serverless: Load command plugin:search
Serverless: Load command emit
Serverless: Load command config
Serverless: Load command config:credentials
Serverless: Load command rollback
Serverless: Load command rollback:function
Serverless: Load command webpack
Serverless: Load command dynamodb
Serverless: Load command dynamodb:migrate
Serverless: Load command dynamodb:seed
Serverless: Load command dynamodb:start
Serverless: Load command dynamodb:noStart
Serverless: Load command dynamodb:remove
Serverless: Load command dynamodb:install
Serverless: Load command offline
Serverless: Load command offline:start
Serverless: Invoke deploy
Serverless: Invoke package
Serverless: Invoke aws:common:validate
Serverless: Invoke aws:common:cleanupTempDir
Serverless: Invoke webpack:validate
Serverless: Invoke webpack:compile
Serverless: Bundling with Webpack...
Time: 874ms
     Asset     Size  Chunks             Chunk Names
handler.js  6.49 kB       0  [emitted]  handler
   [0] ./handler.js 3.65 kB {0} [built]
   [1] external "jwks-rsa" 42 bytes {0} [not cacheable]
   [2] external "jsonwebtoken" 42 bytes {0} [not cacheable]
   [3] external "babel-polyfill" 42 bytes {0} [not cacheable]
Time: 862ms
     Asset     Size  Chunks             Chunk Names
handler.js  6.49 kB       0  [emitted]  handler
   [0] ./handler.js 3.65 kB {0} [built]
   [1] external "jwks-rsa" 42 bytes {0} [not cacheable]
   [2] external "jsonwebtoken" 42 bytes {0} [not cacheable]
   [3] external "babel-polyfill" 42 bytes {0} [not cacheable]
Time: 860ms
     Asset     Size  Chunks             Chunk Names
handler.js  6.49 kB       0  [emitted]  handler
   [0] ./handler.js 3.65 kB {0} [built]
   [1] external "jwks-rsa" 42 bytes {0} [not cacheable]
   [2] external "jsonwebtoken" 42 bytes {0} [not cacheable]
   [3] external "babel-polyfill" 42 bytes {0} [not cacheable]
Serverless: Invoke webpack:package

  Syntax Error -------------------------------------------

  Unexpected end of JSON input

     For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.

  Stack Trace --------------------------------------------

SyntaxError: Unexpected end of JSON input
SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at BbPromise.try (/Users/alopes/Code/Clients/xx-redacted-xx/services/job-user-profiles/node_modules/serverless-webpack/lib/packExternalModules.js:236:47)
    at tryCatcher (/Users/alopes/Code/Clients/xx-redacted-xx/services/job-user-profiles/node_modules/serverless-webpack/node_modules/bluebird/js/release/util.js:16:23)
    at Function.Promise.attempt.Promise.try (/Users/alopes/Code/Clients/xx-redacted-xx/services/job-user-profiles/node_modules/serverless-webpack/node_modules/bluebird/js/release/method.js:39:29)
    at BbPromise.fromCallback.then.depJson (/Users/alopes/Code/Clients/xx-redacted-xx/services/job-user-profiles/node_modules/serverless-webpack/lib/packExternalModules.js:236:35)
    at tryCatcher (/Users/alopes/Code/Clients/xx-redacted-xx/services/job-user-profiles/node_modules/serverless-webpack/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/Users/alopes/Code/Clients/xx-redacted-xx/services/job-user-profiles/node_modules/serverless-webpack/node_modules/bluebird/js/release/promise.js:512:31)
    at Promise._settlePromise (/Users/alopes/Code/Clients/xx-redacted-xx/services/job-user-profiles/node_modules/serverless-webpack/node_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromise0 (/Users/alopes/Code/Clients/xx-redacted-xx/services/job-user-profiles/node_modules/serverless-webpack/node_modules/bluebird/js/release/promise.js:614:10)
    at Promise._settlePromises (/Users/alopes/Code/Clients/xx-redacted-xx/services/job-user-profiles/node_modules/serverless-webpack/node_modules/bluebird/js/release/promise.js:693:18)
    at Promise._fulfill (/Users/alopes/Code/Clients/xx-redacted-xx/services/job-user-profiles/node_modules/serverless-webpack/node_modules/bluebird/js/release/promise.js:638:18)
    at /Users/alopes/Code/Clients/xx-redacted-xx/services/job-user-profiles/node_modules/serverless-webpack/node_modules/bluebird/js/release/nodeback.js:42:21
    at childProcess.exec (/Users/alopes/Code/Clients/xx-redacted-xx/services/job-user-profiles/node_modules/serverless-webpack/lib/packExternalModules.js:233:16)
    at ChildProcess.exithandler (child_process.js:278:5)
    at emitTwo (events.js:125:13)
    at ChildProcess.emit (events.js:213:7)
    at maybeClose (internal/child_process.js:927:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
From previous event:
    at PluginManager.invoke (/Users/alopes/.nvm/versions/node/v8.6.0/lib/node_modules/serverless/lib/classes/PluginManager.js:368:22)
    at PluginManager.spawn (/Users/alopes/.nvm/versions/node/v8.6.0/lib/node_modules/serverless/lib/classes/PluginManager.js:386:17)
    at ServerlessWebpack.BbPromise.bind.then.then.then (/Users/alopes/Code/Clients/xx-redacted-xx/services/job-user-profiles/node_modules/serverless-webpack/index.js:90:51)
    at runCallback (timers.js:781:20)
    at tryOnImmediate (timers.js:743:5)
    at processImmediate [as _immediateCallback] (timers.js:714:5)

  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Forums:        forum.serverless.com
     Chat:          gitter.im/serverless/serverless

  Your Environment Information -----------------------------
     OS:                     darwin
     Node Version:           8.6.0
     Serverless Version:     1.25.0

Offline version

✗ sls offline start
Serverless: Bundling with Webpack...
Time: 762ms
     Asset     Size  Chunks             Chunk Names
handler.js  6.49 kB       0  [emitted]  handler
   [0] ./handler.js 3.65 kB {0} [built]
   [1] external "jwks-rsa" 42 bytes {0} [not cacheable]
   [2] external "jsonwebtoken" 42 bytes {0} [not cacheable]
   [3] external "babel-polyfill" 42 bytes {0} [not cacheable]
Serverless: Watching for changes...
Dynamodb Local Started, Visit: http://localhost:8000/shell
Serverless: DynamoDB - created table jobs-user-profile-dev
Serverless: Starting Offline: dev/eu-west-2.

Serverless: Routes for customAuthorizer:
Serverless: (none)

Serverless: Routes for public:
Serverless: GET /public

Serverless: Routes for private:
Serverless: GET /private
Serverless: Configuring Authorization: private customAuthorizer

Serverless: Offline listening on http://localhost:3051

package.json

  "dependencies": {
    "app-root-path": "^2.0.1",
    "auth0": "^2.5.0",
    "babel-polyfill": "^6.26.0",
    "bluebird": "^3.4.6",
    "globule": "^1.2.0",
    "jsonwebtoken": "^7.4.1",
    "jwks-rsa": "^1.2.1",
    "require-dir": "^0.3.2",
    "serverless-dynamodb-local": "^0.2.27",
    "serverless-offline": "^3.16.0",
    "systemjs": "^0.20.19",
    "webpack": "^3.8.1",
    "webpack-node-externals": "^1.6.0"
  },
  "devDependencies": {
    "babel-cli": "^6.26.0",
    "babel-core": "^6.26.0",
    "babel-loader": "^7.1.2",
    "babel-plugin-istanbul": "^4.1.5",
    "babel-plugin-transform-async-to-generator": "^6.24.1",
    "babel-plugin-transform-class-properties": "^6.24.1",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-stage-0": "^6.24.1",
    "babel-register": "^6.26.0",
    "chai": "^4.1.2",
    "commitizen": "^2.9.6",
    "cross-env": "^5.1.1",
    "cz-conventional-changelog": "^2.1.0",
    "dotenv": "^4.0.0",
    "eslint": "^4.12.0",
    "format-json": "^1.0.3",
    "mocha": "^4.0.1",
    "nyc": "^11.3.0",
    "rimraf": "^2.6.2",
    "semantic-release": "^8.2.0",
    "serverless": "^1.24.1",
    "serverless-dotenv-plugin": "^1.0.1",
    "serverless-webpack": "^4.1.0"
  }

Hi @gastonmorixe, thanks for reporting.

According to the stacktrace, the plugin crashed, because it got an invalid output from the npm ls -prod -json -depth=1 command execution.

Can you try to execute it manually and post the output, so that we can check what exactly is going wrong there?