Node.js Action cannot find config file with relative path

Hi! I’m adding the node.js Github Action and I’m having a very basic issue. This project has existed for a while, and the standard npm install/npm build (or even npm run) work as expected in a development environment.

In the Github Action,
My builds fail due to:

Run npm run build --if-present
> o-fish@0.1.0 build /home/runner/work/o-fish-web/o-fish-web
> react-scripts build

Creating an optimized production build...

Failed to compile.

./src/services/stitch.service.js
Cannot find file '../config' in './src/services'.

The specific line in src/services/stitch.service.js is:
import config from “…/config”;

The src/config.js file exists.

As this is an established project I’d rather not muck around with changing the import to be absolute instead of relative (e.g. something like ./src/config). I’d hate for others to have their builds start failing because I changed that.

I have read this page but it doesn’t address my issue:

What am I missing?

If you need insight into the repository, it’s at


and the workflow is at: .github/workflows/node.js.yml (sorry, I can only post 2 links max because I’m new to the forums.)

Thanks in advance for assistance!

@Sheeri,

The relative path in the script files should relative to the working directory of current step in the job of the workflow.
By default, all the steps in a job are executing in the same default working directory (github.workspace), and this also is the default location of your repository when using the checkout action.

To explain this, here is an example:

  • A .js file in the repository directory, its path is “./src/test-path.js”, see here.

  • A .sh file in the repository directory, its path is “./test.sh”, see here. This bash shell script will be called in the .js file.

  • The workflow file in the repository directory, its path is “./.github/workflows/ci.yml”, see here.

    steps:
      - name: Checkout
        uses: actions/checkout@v2.3.2

# Guess the working directory is the default "github.workspace" when execute the JavaScript file.
# Set the relative path of the bash shell script to be "./test.sh".
      - name: Execute src/test-path.js - 01
        run: node src/test-path.js
        env:
          SH_FILE_PATH: './test.sh'

# Guess the working directory is the directory of the JavaScript file (**./src**) when execute the JavaScript file.
# Set the relative path of the bash shell script to be "../test.sh".
      - name: Execute src/test-path.js - 02
        run: node src/test-path.js
        env:
          SH_FILE_PATH: '../test.sh'

The results:

  • The step “Execute src/test-path.js - 01” can run successfully, see here.
  • The step “Execute src/test-path.js - 02” run failed, see here.

This is a problem because when the repo is checked out, config.js doesn’t exist - config.js.tmpl does. So I had to add to the yaml file to copy the file and update it with the proper values.

@Sheeri,

So I had to add to the yaml file to copy the file and update it with the proper values.

No, you do not need to do this.
You just need to use the working-directory keyword to re-set the working directory of current step, if you do not want to changed any in the .js file.
For example:

      - name: Execute src/test-path.js - 02
        working-directory: ./src
        run: node src/test-path.js
        env:
          SH_FILE_PATH: '../test.sh'

More details, you can see “jobs.<job_id>.steps.run”.

We have a template file, so that people don’t accidentally check-in a config file.

e.g. config.js.tmpl is in the repo, config.js is not (it’s in .gitignore)

So I’m pretty sure I have to copy the config.js.tmpl first (or move it, to rename it).