nektos/act

MODULE_NOT_FOUND during `docker cp` command

pmatheson-greenphire opened this issue ยท 14 comments

Command I'm running
act -P ubuntu-latest=nektos/act-environments-ubuntu:18.04

Error output

 โ˜  git clone 'https://github.com/gittools/actions' # ref=v0.9.2
[]   ๐Ÿณ  docker cp src=/home/user/.cache/act/gittools-actions-gitversion-setup@v0.9.2 dst=/actions/
| internal/modules/cjs/loader.js:985
|   throw err;
|   ^
| 
| Error: Cannot find module '/actions/gittools-actions-gitversion-setup@v0.9.2/dist/github/gitversion/setup/bundle.js'
|     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:982:15)
|     at Function.Module._load (internal/modules/cjs/loader.js:864:27)
|     at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
|     at internal/main/run_main_module.js:18:47 {
|   code: 'MODULE_NOT_FOUND',

it looks like the code from gittools-actions-gitversion-setup@v0.9.2 is copied to /actions/ in the container but the action javascript expects the original directory name to be in the path. So the cp should be cp /home/user/.cache/act/gittools-actions-gitversion-setup@v0.9.2 /actions/gittools-actions-gitversion-setup@v0.9.2

rdlf0 commented

I had some hard time with this, too, but after some digging through the code I found out that in order to get the correct dst path you have to provide the path key in the actions/checkout step like this:

steps:
  - name: Checkout
    uses: actions/checkout@v2
    with:
      path: "your-action-root-directory"

I guess this should be better documented in order to save the others the time I had to spend on looking into it.

This doesn't seem like it would solve the problem - it just changes the destination directory of the initial checkout from /github/workflow/ to /github/workflow/${PATH}

rdlf0 commented

This doesn't seem like it would solve the problem - it just changes the destination directory of the initial checkout from /github/workflow/ to /github/workflow/${PATH}

Yup! And that's how the path provided to cp becomes the one you suggested and the MODULE_NOT_FOUND error is gone. As far as I can understand your issue this seems to be the case. In my situation this was the solution.

The problem is that docker cp interprets .gitignore (see current version), in particular the rule that should not ignore the *.js files in dist/:

!dist/**/*.js

...as if it were a .dockerignore file, which doesn't support exception (!) rules.

So if you check the contents of the copy destination, there is no *.js:

docker exec <act-job-container-name> ls -R /actions/gittools-actions-gitversion-setup@v0.9.2/dist/

A workaround is removing the problematic .gitignore rules in a fork or just deleting .gitignore (which I think act could do before docker cp, @cplee ).

See my fork here: GitTools/actions@master...rstuven:patch-1
You can try it using the action rstuven/actions/gitversion/setup@patch-1 or replicating the change in a fork of your own.

I'm currently having this issue with the same described behaviour when it's working with actions for a .NET Core application.

I am developing on a Windows environment and building on a Linux environment.

[34m[CI Build - Master/build] [0mโญ Run Setup .NET Core
[34m[CI Build - Master/build] [0m โ˜ git clone 'https://github.com/actions/setup-dotnet' # ref=v1
[34m[CI Build - Master/build] [0m ๐Ÿณ docker cp src=act/actions-setup-dotnet@v1 dst=/actions
[34m|[0m internal/modules/cjs/loader.js:628
[34m|[0m throw err;
[34m|[0m ^
[34m|[0m
[34m|[0m Error: Cannot find module '/github/workspace/\actions\actions-setup-dotnet@v1\dist\index.js'
[34m|[0m [90m at Function.Module._resolveFilename (internal/modules/cjs/loader.js:625:15)[39m
[34m|[0m [90m at Function.Module._load (internal/modules/cjs/loader.js:527:27)[39m
[34m|[0m [90m at Function.Module.runMain (internal/modules/cjs/loader.js:839:10)[39m
[34m|[0m [90m at internal/main/run_main_module.js:17:11[39m {
[34m|[0m code: [32m'MODULE_NOT_FOUND'[39m,
[34m|[0m requireStack: []
[34m|[0m }
[34m[CI Build - Master/build] [0m โŒ Failure - Setup .NET Core
Error: exit with FAILURE: 1

similar issue over here too

[CI/Check ubuntu-latest (stable)-1 ]   ๐Ÿณ  docker cp src=act/actions-rs-toolchain@v1 dst=/actions\
| internal/modules/cjs/loader.js:628
|     throw err;
|     ^
|
| Error: Cannot find module '/github/workspace/\actions\actions-rs-toolchain@v1\dist\index.js'
|     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:625:15)
|     at Function.Module._load (internal/modules/cjs/loader.js:527:27)
|     at Function.Module.runMain (internal/modules/cjs/loader.js:839:10)
|     at internal/main/run_main_module.js:17:11 {
|   code: 'MODULE_NOT_FOUND',
|   requireStack: []
| }
[CI/Check ubuntu-latest (stable)-1 ]   โŒ  Failure - actions-rs/toolchain@v1
โžœ  slurpy git:(master) โœ— act -W .github/workflows_test
[Tests CI/tests] ๐Ÿš€  Start image=node:12.6-buster-slim
[Tests CI/tests]   ๐Ÿณ  docker run image=node:12.6-buster-slim entrypoint=["/usr/bin/tail" "-f" "/dev/null"] cmd=[]
[Tests CI/tests]   ๐Ÿณ  docker cp src=/Users/orkhan.mamedov/PycharmProjects/slurpy/. dst=/github/workspace/~/PycharmProjects/slurpy
[Tests CI/tests] โญ  Run Checkout
[Tests CI/tests]   โœ…  Success - Checkout
[Tests CI/tests] โญ  Run build
| /github/workflow/1: line 1: docker: command not found
[Tests CI/tests]   โŒ  Failure - build
Error: exit with `FAILURE`: 127

I had some hard time with this, too, but after some digging through the code I found out that in order to get the correct dst path you have to provide the path key in the actions/checkout step like this:

steps:
  - name: Checkout
    uses: actions/checkout@v2
    with:
      path: "your-action-root-directory"

I guess this should be better documented in order to save the others the time I had to spend on looking into it.

I am currently stuck at the very same thing. I'd like to try your suggestion, but somehow I do not understand what "your-action-root-directory" would be. Could you exemplify which directory I need to put here? And would it be a relative or absolute path on my machine to get act working?

I have a similar question. I'm not sure what "your-action-root-directory" is referring to, because I have no custom actions. Here's a repository I'm working with as an example: https://github.com/tamj0rd2/ts-quickfixes

My ci workflow is defined in .github/workflows/ci.yml. Is that the thing the path is supposed to refer to, or is it something else? Can anyone post a working example of their path parameter and their folder structure?

Here's the error output I'm getting:

[CI/Tests-2] โญ  Run Run headless test
[CI/Tests-2]   โ˜  git clone 'https://github.com/GabrielBB/xvfb-action' # ref=v1.0
[CI/Tests-2]   ๐Ÿณ  docker cp src=/Users/tamara/.cache/act/GabrielBB-xvfb-action@v1.0 dst=/actions/
[CI/Tests-2]   โ—  ::error::Unable to locate executable file: sudo. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.
[CI/Tests-2]   โŒ  Failure - Run headless test
Error: exit with `FAILURE`: 1

@tamj0rd2 your issue is not related to #228. You are using docker image that doesn't have sudo included.

Another scenario to help others debug: running this tool in Windows (from Powershell), I received the following error message when I tried to run an action on ubuntu-18.04:

Error: Cannot find module '/github/workspace/\actions\actions-setup-python@v2\dist\index.js'

Note the slash confusion. As an alternative, I opened up a WSL2-based bash prompt and installed act inside of the Linux subsystem. This resolved the slash problem. and I no longer get the module not found error.

@stephenfuqua that has been fixed in #461

0-sv commented

@rstuven thanks for pointing this out, but I was able to add a !tsconfig.json line to my .gitignore (just in the same repo as the workflow). For some reason tsconfig.json wasn't copied over. So, although you set me on the correct path, I'm not sure if it's still true.