question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Errors when running functions from aws example

See original GitHub issue

Hello, I’m seeing this error when trying to run locally:

$ serverless invoke local -f screenshot
Serverless: Injecting Headless Chrome...
Serverless: WARNING: More than one matching handlers found for 'src/handlers/screenshot'. Using 'src/handlers/screenshot.js'.
Serverless: Bundling with Webpack...
Time: 1746ms
                         Asset    Size  Chunks                    Chunk Names
    src/handlers/screenshot.js  397 kB       0  [emitted]  [big]  src/handlers/screenshot
src/handlers/screenshot.js.map  490 kB       0  [emitted]         src/handlers/screenshot
   [1] external "events" 42 bytes {0} [not cacheable]
   [3] external "http" 42 bytes {0} [not cacheable]
   [8] ./.build/src/utils/log.js 199 bytes {0} [built]
   [9] ./node_modules/chrome-remote-interface/lib/devtools.js 4.44 kB {0} [built]
  [18] ./.build/src/handlers/screenshot.js 668 bytes {0} [built]
  [19] ./node_modules/@serverless-chrome/lambda/dist/bundle.es.js 11.5 kB {0} [built]
  [20] external "fs" 42 bytes {0} [not cacheable]
  [21] external "path" 42 bytes {0} [not cacheable]
  [22] external "child_process" 42 bytes {0} [not cacheable]
  [23] external "net" 42 bytes {0} [not cacheable]
  [24] ./.build/src/handlers/jfmd5owctl4chnsmj95u0izfr___screenshot.js 1.77 kB {0} [built]
  [25] ./.build/src/chrome/screenshot.js 3.38 kB {0} [built]
  [26] ./node_modules/chrome-remote-interface/index.js 1.2 kB {0} [built]
  [29] ./node_modules/chrome-remote-interface/lib/chrome.js 10.5 kB {0} [built]
  [39] ./.build/src/utils/sleep.js 217 bytes {0} [built]
    + 25 hidden modules

WARNING in ./node_modules/ws/lib/BufferUtil.js
Module not found: Error: Can't resolve 'bufferutil' in '/Users/jonhkr/serverless/aws/node_modules/ws/lib'
 @ ./node_modules/ws/lib/BufferUtil.js 35:21-42
 @ ./node_modules/ws/lib/Receiver.js
 @ ./node_modules/ws/index.js
 @ ./node_modules/chrome-remote-interface/lib/chrome.js
 @ ./node_modules/chrome-remote-interface/index.js
 @ ./.build/src/chrome/screenshot.js
 @ ./.build/src/handlers/jfmd5owctl4chnsmj95u0izfr___screenshot.js
 @ ./.build/src/handlers/screenshot.js

WARNING in ./node_modules/@serverless-chrome/lambda/dist/bundle.es.js
Module not found: Error: Can't resolve 'chrome-launcher' in '/Users/jonhkr/serverless/aws/node_modules/@serverless-chrome/lambda/dist'
 @ ./node_modules/@serverless-chrome/lambda/dist/bundle.es.js 291:52-78
 @ ./.build/src/handlers/screenshot.js

WARNING in ./node_modules/ws/lib/Validation.js
Module not found: Error: Can't resolve 'utf-8-validate' in '/Users/jonhkr/serverless/aws/node_modules/ws/lib'
 @ ./node_modules/ws/lib/Validation.js 10:22-47
 @ ./node_modules/ws/lib/Receiver.js
 @ ./node_modules/ws/index.js
 @ ./node_modules/chrome-remote-interface/lib/chrome.js
 @ ./node_modules/chrome-remote-interface/index.js
 @ ./.build/src/chrome/screenshot.js
 @ ./.build/src/handlers/jfmd5owctl4chnsmj95u0izfr___screenshot.js
 @ ./.build/src/handlers/screenshot.js
Error occured in serverless-plugin-chrome wrapper when trying to ensure Chrome for default() handler. { flags: [ '--window-size=1280x1696', '--hide-scrollbars' ],
  chromePath: '/var/task/headless-chromium' } Error: @serverless-chrome/lambda: Unable to find "chrome-launcher". Make sure it's installed if you wish to develop locally.
    at /Users/jonhkr/serverless/aws/.build/.webpack/service/src/handlers/screenshot.js:3211:17
    at next (native)
    at step (/Users/jonhkr/serverless/aws/.build/.webpack/service/src/handlers/screenshot.js:3171:191)
    at /Users/jonhkr/serverless/aws/.build/.webpack/service/src/handlers/screenshot.js:3171:437
    at /Users/jonhkr/serverless/aws/.build/.webpack/service/src/handlers/screenshot.js:3171:99
    at launch (/Users/jonhkr/serverless/aws/.build/.webpack/service/src/handlers/screenshot.js:3268:17)
    at ensureHeadlessChrome (/Users/jonhkr/serverless/aws/.build/.webpack/service/src/handlers/screenshot.js:2897:59)
    at AwsInvokeLocal.invokeLocalNodeJs (/Users/jonhkr/.nvm/versions/node/v6.10.3/lib/node_modules/serverless/lib/plugins/aws/invokeLocal/index.js:331:12)
    at AwsInvokeLocal.invokeLocal (/Users/jonhkr/.nvm/versions/node/v6.10.3/lib/node_modules/serverless/lib/plugins/aws/invokeLocal/index.js:125:19)
    at AwsInvokeLocal.tryCatcher (/Users/jonhkr/.nvm/versions/node/v6.10.3/lib/node_modules/serverless/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/Users/jonhkr/.nvm/versions/node/v6.10.3/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:512:31)
    at Promise._settlePromise (/Users/jonhkr/.nvm/versions/node/v6.10.3/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromise0 (/Users/jonhkr/.nvm/versions/node/v6.10.3/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:614:10)
    at Promise._settlePromises (/Users/jonhkr/.nvm/versions/node/v6.10.3/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:693:18)
    at Async._drainQueue (/Users/jonhkr/.nvm/versions/node/v6.10.3/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:133:16)
    at Async._drainQueues (/Users/jonhkr/.nvm/versions/node/v6.10.3/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:143:10)
    at Immediate.Async.drainQueues (/Users/jonhkr/.nvm/versions/node/v6.10.3/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:17:14)
    at runCallback (timers.js:672:20)
    at tryOnImmediate (timers.js:645:5)
    at processImmediate [as _immediateCallback] (timers.js:617:5)

It seems the package chrome-laucher is not available, then I install it and get another error:

$ npm install chrome-launcher
aws@1.0.0-29 /Users/jonhkr/serverless/aws
└─┬ chrome-launcher@0.9.0 
  ├── @types/core-js@0.9.43 
  ├── @types/mkdirp@0.3.29 
  ├── @types/node@6.0.66 
  ├── @types/rimraf@0.0.28 
  └── lighthouse-logger@1.0.1 

$ serverless invoke local -f screenshot
Serverless: Injecting Headless Chrome...
Serverless: WARNING: More than one matching handlers found for 'src/handlers/screenshot'. Using 'src/handlers/screenshot.js'.
Serverless: Bundling with Webpack...
Time: 1974ms
                         Asset    Size  Chunks                    Chunk Names
    src/handlers/screenshot.js  572 kB       0  [emitted]  [big]  src/handlers/screenshot
src/handlers/screenshot.js.map  702 kB       0  [emitted]         src/handlers/screenshot
   [0] external "fs" 42 bytes {0} [not cacheable]
   [1] external "path" 42 bytes {0} [not cacheable]
   [4] external "child_process" 42 bytes {0} [not cacheable]
   [8] external "net" 42 bytes {0} [not cacheable]
  [23] ./node_modules/chrome-launcher/utils.js 6.09 kB {0} [built]
  [25] ./.build/src/utils/log.js 199 bytes {0} [built]
  [26] ./node_modules/chrome-remote-interface/lib/devtools.js 4.44 kB {0} [built]
  [35] ./.build/src/handlers/screenshot.js 668 bytes {0} [built]
  [36] ./node_modules/@serverless-chrome/lambda/dist/bundle.es.js 11.5 kB {0} [built]
  [37] ./node_modules/chrome-launcher/index.js 412 bytes {0} [optional] [built]
  [38] ./node_modules/chrome-launcher/chrome-launcher.js 25.1 kB {0} [built]
  [58] ./.build/src/handlers/eyzctkbro7uq2bptzwlq8h0k9___screenshot.js 1.77 kB {0} [built]
  [59] ./.build/src/chrome/screenshot.js 3.38 kB {0} [built]
  [60] ./node_modules/chrome-remote-interface/index.js 1.2 kB {0} [built]
  [72] ./.build/src/utils/sleep.js 217 bytes {0} [built]
    + 58 hidden modules

WARNING in ./node_modules/ws/lib/BufferUtil.js
Module not found: Error: Can't resolve 'bufferutil' in '/Users/jonhkr/serverless/aws/node_modules/ws/lib'
 @ ./node_modules/ws/lib/BufferUtil.js 35:21-42
 @ ./node_modules/ws/lib/Receiver.js
 @ ./node_modules/ws/index.js
 @ ./node_modules/chrome-remote-interface/lib/chrome.js
 @ ./node_modules/chrome-remote-interface/index.js
 @ ./.build/src/chrome/screenshot.js
 @ ./.build/src/handlers/eyzctkbro7uq2bptzwlq8h0k9___screenshot.js
 @ ./.build/src/handlers/screenshot.js

WARNING in ./node_modules/ws/lib/Validation.js
Module not found: Error: Can't resolve 'utf-8-validate' in '/Users/jonhkr/serverless/aws/node_modules/ws/lib'
 @ ./node_modules/ws/lib/Validation.js 10:22-47
 @ ./node_modules/ws/lib/Receiver.js
 @ ./node_modules/ws/index.js
 @ ./node_modules/chrome-remote-interface/lib/chrome.js
 @ ./node_modules/chrome-remote-interface/index.js
 @ ./.build/src/chrome/screenshot.js
 @ ./.build/src/handlers/eyzctkbro7uq2bptzwlq8h0k9___screenshot.js
 @ ./.build/src/handlers/screenshot.js
@serverless-chrome/lambda Spawning headless shell
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
@serverless-chrome/lambda Error trying to spawn chrome: TypeError: Cannot read property 'toString' of undefined
    at Launcher.<anonymous> (/Users/jonhkr/serverless/aws/.build/.webpack/service/src/handlers/screenshot.js:6173:63)
    at next (native)
    at /Users/jonhkr/serverless/aws/.build/.webpack/service/src/handlers/screenshot.js:6016:71
    at __awaiter (/Users/jonhkr/serverless/aws/.build/.webpack/service/src/handlers/screenshot.js:6012:12)
    at spawnPromise (/Users/jonhkr/serverless/aws/.build/.webpack/service/src/handlers/screenshot.js:6158:41)
    at Launcher.<anonymous> (/Users/jonhkr/serverless/aws/.build/.webpack/service/src/handlers/screenshot.js:6176:16)
    at next (native)
    at /Users/jonhkr/serverless/aws/.build/.webpack/service/src/handlers/screenshot.js:6016:71
    at __awaiter (/Users/jonhkr/serverless/aws/.build/.webpack/service/src/handlers/screenshot.js:6012:12)
    at Launcher.spawnProcess (/Users/jonhkr/serverless/aws/.build/.webpack/service/src/handlers/screenshot.js:6156:16)
    at Launcher.<anonymous> (/Users/jonhkr/serverless/aws/.build/.webpack/service/src/handlers/screenshot.js:6151:35)
    at throw (native)
    at rejected (/Users/jonhkr/serverless/aws/.build/.webpack/service/src/handlers/screenshot.js:6014:65)
    at process._tickDomainCallback (internal/process/next_tick.js:135:7)
@serverless-chrome/lambda stdout log: 
@serverless-chrome/lambda stderr log: 
Error occured in serverless-plugin-chrome wrapper when trying to ensure Chrome for default() handler. { flags: [ '--window-size=1280x1696', '--hide-scrollbars' ],
  chromePath: '/var/task/headless-chromium' } Error: Unable to start Chrome. If you have the DEBUG env variable set,there will be more in the logs.
    at /Users/jonhkr/serverless/aws/.build/.webpack/service/src/handlers/screenshot.js:5939:13
    at throw (native)
    at step (/Users/jonhkr/serverless/aws/.build/.webpack/service/src/handlers/screenshot.js:5880:191)
    at /Users/jonhkr/serverless/aws/.build/.webpack/service/src/handlers/screenshot.js:5880:402
    at process._tickDomainCallback (internal/process/next_tick.js:135:7)
events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: spawn /var/task/headless-chromium ENOENT
    at exports._errnoException (util.js:1018:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32)
    at onErrorNT (internal/child_process.js:367:16)
    at _combinedTickCallback (internal/process/next_tick.js:80:11)
    at process._tickDomainCallback (internal/process/next_tick.js:128:9)

I was also getting Internal server error on deployed functions.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

13reactions
ChrisGibbcommented, Jun 25, 2018

If you look in node_modules/serverless-plugin-chrome/README.md of your project you will see a section Local Development.

“Local development is supported. You must install the chrome-launcher package in your project. A locally installed version of Chrome will be launched.”

So I did:

 npm install --dev chrome-launcher

and now it works

11reactions
SidneyNemzercommented, Sep 13, 2018

Looks like #104 will fix this. In the meantime, I’ve had to manually modify node_modules/@serverless-chrome/lambda/dist/bundle.es.js, commenting out line 348. Now I’m able to run the function and launch chrome locally.

chromeInstance = new LocalChromeLauncher({
  // chromePath, // <-- line 348
  chromeFlags: flags,
  port
});

That line is probably needed when running on AWS so don’t forget to un-comment before deploying.

EDIT: On Windows, I’m still running into this error, which occurs after the function runs. But at least I can run it.

EDIT 2: You may need to change bundle.cjs.js depending on your build system. Also, partially solved problem from my previous edit, see my comment in that issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I handle errors in serverless applications? - AWS
In this tutorial, you will learn how to use AWS Step Functions to handle workflow runtime errors. AWS Step Functions is a serverless...
Read more >
How do I troubleshoot Lambda function failures? - AWS
To troubleshoot Lambda function failures, first determine what's causing the error by using one or more of the AWS services and features ...
Read more >
AWS Lambda function errors in Node.js
This page describes how to view Lambda function invocation errors for the Node.js runtime using the Lambda console and the AWS CLI.
Read more >
Error handling in Step Functions - AWS Documentation
Error handling in Step Functions. Any state can encounter runtime errors. Errors can happen for various reasons, such as the following examples:.
Read more >
Error handling and automatic retries in AWS Lambda
When you invoke a function, two types of error can occur. Invocation errors occur when the invocation request is rejected before your function...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found