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
[email protected] /Users/jonhkr/serverless/aws
โโโฌ [email protected]
โโโ @types/[email protected]
โโโ @types/[email protected]
โโโ @types/[email protected]
โโโ @types/[email protected]
โโโ [email protected]
$ 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.
same here :) thanks Adienuadieu, please look into it
I think I found the issue
Error: spawn /var/task/headless-chromium ENOENT
Looks like it is trying to spawn the chromium from /var/task which is where it is stored in the lambda environment, but as I was trying to run it locally, there is no binary there.
I have a very similar error, but trying to run on lambda:
2017-12-12T01:11:25.034Z 5edd99a7-ded9-11e7-899b-f57efaedd856 Error: spawn /var/task/capture/node_modules/@serverless-chrome/lambda/dist/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)
Getting the same issue, is there any easy way to specify the chromePath?
+1 unable to invoke local chrome :(
@serverless-chrome/lambda Spawning headless shellshell-init: error retrieving current directory: getcwd: cannot access parent di
rectories: No such file or directory@serverless-chrome/lambda Error trying to spawn chrome: TypeError: Cannot read
property 'toString' of undefined
Error occured in serverless-plugin-chrome wrapper when trying to ensure Chromefor 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.
Anyway to set this path ?
Same here when I run on AWS.
{"message": "Internal server error"}
Only the version-info lambda works.
A very simple solution that comes to mind when trying to get chrome to run locally:
sudo ln -s /usr/bin/google-chrome-stable /var/task/headless-chromium
Make sure the path to binary and the var task folder are properly set on your system.
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
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.
Most helpful comment
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.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.jsdepending on your build system. Also, partially solved problem from my previous edit, see my comment in that issue.