tbroadley / spellchecker-cli

A command-line tool for spellchecking files.
MIT License
119 stars 16 forks source link

GitHub Action - TypeError: Cannot read properties of undefined (reading 'filename') #94

Closed nicholaswilde closed 2 years ago

nicholaswilde commented 2 years ago

I'm trying to run spellchecker-cli in a GitHub Action that runs a script in my repo to spellcheck all of my markdown files. After the 5.0.0 update, my GH Action no longer works. Do you have any idea on how I can fix it?

spellcheck.yaml

---
name: spellcheck
on:  # yamllint disable-line rule:truthy
  workflow_dispatch:
  pull_request:
  push:
    branches:
      - main

jobs:
  spellcheck:
    name: spellcheck
    runs-on: ubuntu-20.04

    steps:
      - name: Checkout repo
        uses: actions/checkout@v3
      - name: Setup npm
        uses: actions/setup-node@v3
      - name: Setup spellchecker
        run: npm install --location=global spellchecker-cli
      - run: npm list --global spellchecker-cli
      - name: Run spellcheck
        run: ./scripts/spellcheck.sh

Failed GH Action Output

Run ./scripts/spellcheck.sh
  ./scripts/spellcheck.sh
  shell: /usr/bin/bash -e {0}
/usr/local/lib/node_modules/spellchecker-cli/node_modules/app-root-path/lib/resolve.js:111
        appRootPath = path.dirname(requireFunction.main.filename);
                                                        ^
TypeError: Cannot read properties of undefined (reading 'filename')
    at resolve (/usr/local/lib/node_modules/spellchecker-cli/node_modules/app-root-path/lib/resolve.js:111:51)
    at module.exports (/usr/local/lib/node_modules/spellchecker-cli/node_modules/app-root-path/lib/app-root-path.js:6:[2](https://github.com/nicholaswilde/recipes/runs/7424402249?check_suite_focus=true#step:6:2)0)
    at Object.<anonymous> (/usr/local/lib/node_modules/spellchecker-cli/node_modules/app-root-path/index.js:4:18)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:[3](https://github.com/nicholaswilde/recipes/runs/7424402249?check_suite_focus=true#step:6:3)2)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:170:29)
    at ModuleJob.run (node:internal/modules/esm/module_job:198:2[5](https://github.com/nicholaswilde/recipes/runs/7424402249?check_suite_focus=true#step:6:6))
    at async Promise.all (index 0)
Error: Process completed with exit code 1.

Working GH Action Output

Run ./scripts/spellcheck.sh
  ./scripts/spellcheck.sh
  shell: /usr/bin/bash -e {0}
Spellchecking [3](https://github.com/nicholaswilde/recipes/runs/7345592539?check_suite_focus=true#step:5:3)[4](https://github.com/nicholaswilde/recipes/runs/7345592539?check_suite_focus=true#step:5:5)[6](https://github.com/nicholaswilde/recipes/runs/7345592539?check_suite_focus=true#step:5:7) files...
./cook/asian/Coconut Curried Vegetables with Rice.cook: no issues found
./cook/asian/Cool and Spicy Noodle Salad.cook: no issues found
./cook/asian/Crispy Peanut Tofu & Cauliflower Rice Stir-Fry.cook: no issues found
./cook/asian/Everyday Chinese Vegetable Stir-Fry.cook: no issues found
./cook/asian/Noodle-Free Pad Thai.cook: no issues found
./cook/beverages/Iced Chai Latte.cook: no issues found
./cook/beverages/Old Irish Coffee.cook: no issues found
./cook/beverages/Olde Tyme Lemonade.cook: no issues found
./cook/breads/Best-Ever Banana Bread.cook: no issues found
./cook/breads/Bread Machine French Bread.cook: no issues found
...

spellcheck.sh

#!/bin/bash
set -e
set -o pipefail
shopt -s globstar
shopt -s dotglob nullglob

a=$(git rev-parse --show-toplevel)
cd "${a}"
spellchecker -d dictionary.txt -f {"./cook/**/*.cook","./docs/**/*.md"}

It works locally on my machine with version 5.0.0.

npm list --global spellchecker-cli
/home/linuxbrew/.linuxbrew/lib
└── spellchecker-cli@5.0.0
tbroadley commented 2 years ago

Thanks for the issue! This looks like a duplicate of #91.

nicholaswilde commented 2 years ago

Yep, the issue is related.

I was able to solve the issue by installing the package locally and then running npx spellchecker inside of my script.

npm install spellchecker-cli
npx spellchecker <file>

Thanks for the help.

Side note, I never know if I should post the solution to the thread I started or in the parent duplicate issue. Any thoughts?

tbroadley commented 2 years ago

Side note, I never know if I should post the solution to the thread I started or in the parent duplicate issue. Any thoughts?

Good question. I think I'd normally post my solution in both issues. Or at least add a comment to one issue with a link to my comment in the other.