Serverless-chrome: Create failing with ENOENT: no such file or directory

Created on 24 Dec 2017  路  16Comments  路  Source: adieuadieu/serverless-chrome

I'm trying to install on Windows, and whether I use cygwin or the native shell I run into this problem trying to create the service:

Jim-PC17 495 ~/workspace/jetsam$ serverless create -u https://github.com/adieuadieu/serverless-chrome/tree/master/examples/serverless-framework/ aws
Serverless: Generating boilerplate...
Serverless: Downloading and installing "examples\serverless-framework\aws"...

  Serverless Error ---------------------------------------

  Error: ENOENT: no such file or directory, link 'C:\Users\Jim\workspace\dist' -> 'C:\cygwin64\tmp\serverless-chrome\packages\lambda\integration-test\dist'

  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:                     win32
     Node Version:           8.9.3
     Serverless Version:     1.24.1

I'm new to this stack, and I'm not sure if that cryptic error message means it can't make a symlink or can't find a symlink, or if it's suggesting I make one. What I have figured out:

  1. C:\Users\Jim\workspace\dist doesn't exist (and probably shouldn't be created, as it's outside the directory I'm trying to install into).
  2. C:\cygwin64\tmp\serverless-chrome\packages\lambda\integration-test does exist but has no dist subdir.
  3. I see in github dist is supposed to be a symlink that points up the tree, but I don't see its target in github. Maybe it's supposed to be created during the install? I haven't figured out how to turn on enough logging to follow the install process.
bug

Most helpful comment

Any updates on this?

All 16 comments

Any workarounds for this? I've tried a few things, including:

Run in GitBash as administrator
Gives same error as reported by @jkellyinsf

Run in PowerShell as administrator
Gives same error as reported by @jkellyinsf

Clone the repo ([email protected]:adieuadieu/serverless-chrome.git) then invoke local version-info as administrator

I had to install chrome-launcher - shouldn't this be a dev dependency by default?

In any case, once chrome-launcher is installed, I get the following error:

ENOTEMPTY: directory not empty, rmdir '~/code/serverless-chrome/examples/serverless-framework/aws/.build/.webpack'

I manually removed the .webpack directory and retried invoking the service locally, but got the same error. Here's the full output:

$ serverless invoke local -f version-info
Serverless: Injecting Headless Chrome...
Serverless: Bundling with Webpack...
Time: 1848ms
                      Asset    Size  Chunks                    Chunk Names
    src/handlers/version.js  579 kB       0  [emitted]  [big]  src/handlers/version
src/handlers/version.js.map  713 kB       0  [emitted]         src/handlers/version
   [0] external "fs" 42 bytes {0} [not cacheable]
   [1] external "path" 42 bytes {0} [not cacheable]
   [2] ./node_modules/@serverless-chrome/lambda/dist/bundle.es.js 11.5 kB {0} [built]
   [5] external "child_process" 42 bytes {0} [not cacheable]
  [10] external "net" 42 bytes {0} [not cacheable]
  [35] ./.build/src/handlers/version.js 651 bytes {0} [built]
  [36] ./node_modules/chrome-launcher/index.js 412 bytes {0} [optional] [built]
  [37] ./node_modules/chrome-launcher/chrome-launcher.js 25.5 kB {0} [built]
  [47] ./node_modules/chrome-launcher/chrome-finder.js 17.8 kB {0} [built]
  [55] ./node_modules/chrome-launcher/random-port.js 1.92 kB {0} [built]
  [56] ./node_modules/chrome-launcher/flags.js 2.09 kB {0} [built]
  [57] ./.build/src/handlers/1k819a6djhn___version.js 651 bytes {0} [built]
  [58] ./.build/src/handlers/vm9pl8nfv3l___version.js 651 bytes {0} [built]
  [59] ./.build/src/handlers/ueyt7nxxsun___version.js 651 bytes {0} [built]
  [60] ./.build/src/handlers/ojwh36dqtcj___version.js 651 bytes {0} [built]
    + 62 hidden modules

WARNING in ./node_modules/ws/lib/BufferUtil.js
Module not found: Error: Can't resolve 'bufferutil' in '~/code/serverless-chrome/examples/serverless-framework/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/version.js
 @ ./.build/src/handlers/6kk7p2zprlubqnxa33vkc07ldi___version.js
 @ ./.build/src/handlers/r5h7afteshk___version.js
 @ ./.build/src/handlers/ojwh36dqtcj___version.js
 @ ./.build/src/handlers/ueyt7nxxsun___version.js
 @ ./.build/src/handlers/vm9pl8nfv3l___version.js
 @ ./.build/src/handlers/1k819a6djhn___version.js
 @ ./.build/src/handlers/version.js

WARNING in ./node_modules/ws/lib/Validation.js
Module not found: Error: Can't resolve 'utf-8-validate' in '~/code/serverless-chrome/examples/serverless-framework/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/version.js
 @ ./.build/src/handlers/6kk7p2zprlubqnxa33vkc07ldi___version.js
 @ ./.build/src/handlers/r5h7afteshk___version.js
 @ ./.build/src/handlers/ojwh36dqtcj___version.js
 @ ./.build/src/handlers/ueyt7nxxsun___version.js
 @ ./.build/src/handlers/vm9pl8nfv3l___version.js
 @ ./.build/src/handlers/1k819a6djhn___version.js
 @ ./.build/src/handlers/version.js
@serverless-chrome/lambda Spawning headless shell

  Error --------------------------------------------------

  ENOTEMPTY: directory not empty, rmdir '~/code/serverless-chrome/examples/serverless-framework/aws/.build/.webpack'

     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:                     win32
     Node Version:           9.3.0
     Serverless Version:     1.25.0

My next step will be to try to rebuild the version-info function from scratch to see if I can spot any issues or get it working.

Any other suggestions for diagnosing/fixing/working-around this issue?

Any updates on this?

Still doesn't work. Maybe I have to migrate to Linux?..

Installed Linux, problem has gone.

I have this issue on Mac. Any updates?

I also face the same error, any updates?

Having the same issue on Windows

@jamestharpe it looks like the work-around is deleting the .build folder manually after locally invoking a function. That's what serverless-plugin-chrome is trying to do here, but failing with the permission issue on Windows.

EDIT: According to Windows' Resource Monitor, the process locking the file is... node. Not sure how to debug from here though.

EDIT 2: I modified the serverless-chrome-plugin package in my local node modules, removing the unlink call in the cleanup() function and adding a call to fs.emptyDirSync, from fs-extra, in beforeCreateDeploymentArtifacts. The effect is the build folder is removed BEFORE running the function, instead of after. Still not sure how to debug what is locking the folder.

I think your error is actually different than @jkellyinsf's error, so maybe you should open a separate issue?

I get the issue on Ubuntu Linux and Windows, here is my error log for Ubuntu Linux running on CodeBuild. Doesn't happen on my Mac machine :(

  ENOENT: no such file or directory, link '/codebuild/output/src741193932/src/git-codecommit.us-east-1.amazonaws.com/v1/repos/aperture.direct/backend/.build/functions/puppeteer/XXXXXXX.js' -> '/codebuild/output/src741193932/src/git-codecommit.us-east-1.amazonaws.com/v1/repos/aperture.direct/backend/.build/functions/puppeteer/hbmlz4z2vtw___XXXXXXX.js'

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

  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Issues:        forum.serverless.com

  Your Environment Information -----------------------------
     OS:                     linux
     Node Version:           8.11.0
     Serverless Version:     1.32.0

I pinned point this error from this function: https://github.com/adieuadieu/serverless-chrome/blob/master/packages/serverless-plugin/src/index.js#L180

the destination file does not exists (however the folder exists - .build/src/handlers in my case) and it looks like fs-p package (which is deprecated - last update 2 years ago) is not really good at handling this. Any reason why we use this package?

Problem still exists. I am on Windows 10, trying to run serverless in Windows Subsystem for Linux (WSL). Fails on random files every build attempt, never the same file.

I managed a workaround. Docker. I built a Dockerfile and companion helper shell script. Now, everything is working like a boss.

I didn't include the package.json build command or sls-build.sh script, but ultimately they execute the sls command to deploy.

# start with the target node runtime
FROM node:8.10.0

# copy top-level monorepo package information
WORKDIR /usr/src/app
COPY package.json .
COPY yarn.lock .

# copy lambda functions
WORKDIR /usr/src/app/backend
COPY backend/package.json .
COPY backend/serverless.yml .
COPY backend/tsconfig.json .
COPY backend/yarn.lock .
COPY backend/aws ./aws
COPY backend/functions ./functions
COPY backend/scripts ./scripts

# make serverless build script executable
RUN chmod +x ./scripts/sls-build.sh

# install the complete app
RUN yarn install

# dynamic environment variables from --build-arg
ARG aws_access_key_id
ARG aws_secret_access_key
ARG aws_region
ARG node_env

# set env variables
ENV AWS_ACCESS_KEY_ID=$aws_access_key_id
ENV AWS_REGION=$aws_region
ENV AWS_SECRET_ACCESS_KEY=$aws_secret_access_key
ENV AWS_XRAY_CONTEXT_MISSING=LOG_ERROR
ENV NODE_ENV=$node_env
ENV SERVICE_NAME=your-service-name

# run the deployment
ENTRYPOINT exec yarn run lambda:deploy

Companion shell script

#!/bin/bash

# set variable defaults
key=
env=sandbox
region=us-east-1
secret=

# get variable overrides from the CLI
while [ $# -gt "0" ];
do
  case $1 in
    -e=*|--env=*) env="${1#*=}";;
    -k=*|--key=*) key="${1#*=}";;
    -r=*|--region=*) region="${1#*=}";;
    -s=*|--secret=*) secret="${1#*=}";;
  esac
  shift
done;

# build the docker image
echo "Building docker image..."
  (
    docker build \
      --build-arg aws_access_key_id=$key \
      --build-arg aws_secret_access_key=$secret \
      --build-arg aws_region=$region \
      --build-arg node_env=$env \
      -t lambda .
  ) || exit $?

# run it
echo "Running the deployment..."
  (docker run lambda) || exit $?

Example usage:

bash build.sh -k=aws-access-key -s=aws-secret

Still having this issue

I think I've found a practical work-around.
This issue is caused because Windows uses NTFS and its link system is little bit diffrent from that of Unix systems. So we can make a junction before serverless-plugin-chrome makes a symbolic link.

Add this script in your package.json.

"scripts": {
  "deploy-win": "MKDIR .build && MKLINK /j .build\\node_modules node_modules && sls deploy"
}

And Type this in your bash to deploy.

> npm run deploy-win

I got it work on Windows with WSL: https://docs.microsoft.com/en-US/windows/wsl/install-win10

After installing WSL you can start a Linux terminal:
wsl -u root

Delete the Serveles build Folder and serveless Folder. then try to deploy

Was this page helpful?
0 / 5 - 0 ratings