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.

[BUG] No such file or directory (...../../bin/chromium.br)

See original GitHub issue

Environment

  • chrome-aws-lambda Version: 2.0.1
  • puppeteer / puppeteer-core Version: 2.0.0/2.0.0
  • OS: Built on Fedora 29, NodeJS 10.17.0, Serverless 1.58.0, serveless-webpack 5.3.1
  • Node.js Version: 10.x
  • Lambda / GCF Runtime: Lambda

Expected Behavior

Chromium should have been launched

Current Behavior

Inflating chromium raised an error:

2019-11-25T21:11:33.586Z	233af41f-a717-499e-818f-08acb732ee55	INFO	{ [Error: ENOENT: no such file or directory, open 'node_modules/chrome-aws-lambda/source/../bin/chromium.br']
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: 'node_modules/chrome-aws-lambda/source/../bin/chromium.br' }

Possible Solution

Use let input = join(__dirname, '..', 'bin'); here

Steps to Reproduce

Create a webpack + serverless package that does not use layers, ie. the compressed files are included in the package at node_modules/chrome-aws-lambda/bin

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

10reactions
mattiasnixellcommented, Mar 30, 2020

Hi, I bumped into this issue as well. @campidelli, your solution works best if there’s only 1 entry in the Webpack config. However, if one wants to bundle multiple functions (e.g. serverless’ slsw.lib.entries using “package individually”), the binary files will be copied to every function’s bundle. If one only need chromium in 1 function, this behavior will occupy unnecessary storage from their AWS lambda shared code storage.

I propose to use Webpack’s file-loader instead so that one gains more control of which function bundles should include chromium. I’m using the following Webpack config currently:

const slsw = require('serverless-webpack');

module.exports = {
  entry: slsw.lib.entries,
  module: {
    rules: [
      {
        test: /\.ts$/,
        use: [{ loader: 'ts-loader', options: { transpileOnly: true } }],
      },
      /**
       * Use file loader to move chromium .br files into /bin
       * @link https://github.com/alixaxel/chrome-aws-lambda/issues/80
       */
      {
        test: /\.br$/,
        use: [{ loader: 'file-loader', options: { name: '/bin/[name].[ext]' } }],
      },
    ],
  },
  node: {
    // Make sure that __dirname works in node env
    __dirname: true,
  },
  resolve: {
    extensions: ['.ts', '.js'],
  },
  stats: {
    /* @link https://www.npmjs.com/package/ts-loader#transpileonly-boolean-defaultfalse */
    warningsFilter: /export .* was not found in/,
  },
  target: 'node',
};

…and then add these imports to the top of the handler file where you need chromium:

import 'chrome-aws-lambda/bin/aws.tar.br';
import 'chrome-aws-lambda/bin/chromium.br';
import 'chrome-aws-lambda/bin/swiftshader.tar.br';

I hope someone finds this useful, and thanks @campidelli for your solution and pointers 🙂

7reactions
campidellicommented, Dec 8, 2019

Hi there, just in case this problem happens to anyone else, I worked around it by configuring my webpack.config.js as follows:

var CopyWebpackPlugin = require('copy-webpack-plugin');

module.exports = {
  entry: './handler.js',
  target: 'node',
  module: {
    loaders: [{
      test: /\.js$/,
      loaders: ['babel-loader'],
      include: __dirname,
      exclude: /node_modules/,
    }]
  },
  output: {
    libraryTarget: 'commonjs',
    path: __dirname + '/.webpack',
    filename: 'handler.js'
  },
  externals: {
    'chrome-aws-lambda': 'chrome-aws-lambda',
    'lambdafs': 'lambdafs',
  },
  plugins: [
    new CopyWebpackPlugin([
      { from: 'node_modules/chrome-aws-lambda', to: 'node_modules/chrome-aws-lambda' },
      { from: 'node_modules/lambdafs', to: 'node_modules/lambdafs' },
    ])
  ]
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

Chrome Binary Not Found on AWS Lambda Using Serverless ...
Chrome Binary Not Found on AWS Lambda Using Serverless and chrome-aws-lambda Node package ; "errorMessage": "ENOENT: no such file or directory, ...
Read more >
Netlify functions + Headless Chrome - Support
site: mevorach Problem: Trying to use Headless Chrome to get a website's title and ... no such file or directory, open '/var/task/netlify/bin/chromium.br'] ...
Read more >
CSCvh04263 - Critical mkdir failed error seen in ... - Cisco Bug
Beta testing Symptom: We see failures to create directories while joining the domain on WSA. Wed Dec 6 15:47:10 2017 Debug: PROX_AUTH ...
Read more >
pipewire pactl no such file or directory - Launchpad Bugs
fresh kinetic install pw.conf execvp error pactl no such file or directory is it supposed to be there? error from pipewire.
Read more >
Moodle in English: Cache warning bug
... failed to open stream: No such file or directory in ... I have not yet managed to trigger the bug though. ----------------------------....
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