Poetry/mkdocs build & deploy failing. Build script returned non-zero exit code: 2. mkdocs: command not found

My deploy/build has started failing again — this appears to be the same issue that occurred 2 weeks ago raised here:

Creating a new thread since those are marked as solved, and i didn’t get a response when commenting in the replies.

My config has not changed, it was working fine then spontaneously stopped as it did 2 weeks ago.

My project is built using mkdocs and deploys using poetry. Errors below:

1:04:18 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
1:04:18 PM: Writing lock file
1:04:18 PM: Installing the current project: XXX (1.0.0)
1:04:18 PM: Warning: The current project could not be installed: No file/folder found for package XXX
1:04:18 PM: If you do not want to install the current project use --no-root.
1:04:18 PM: If you want to use Poetry only for dependency management but not for packaging, you can disable package mode by setting package-mode = false in your pyproject.toml file.
1:04:18 PM: In a future version of Poetry this warning will become an error!
1:04:18 PM: bash: line 4: mkdocs: command not found
1:04:18 PM: ​
1:04:18 PM: "build.command" failed                                        
1:04:18 PM: ────────────────────────────────────────────────────────────────
1:04:18 PM: ​
1:04:18 PM:   Error message
1:04:18 PM:   Command failed with exit code 127: pip3 install -q poetry && (https://ntl.fyi/exit-code-127)
1:04:18 PM:   python -m poetry &&
1:04:18 PM:   poetry config virtualenvs.in-project true &&
1:04:18 PM:   poetry install -v &&
1:04:18 PM:   mkdocs build
1:04:18 PM: ​​
1:04:18 PM:   Error location
1:04:18 PM:   In build.command from netlify.toml:
1:04:18 PM:   pip3 install -q poetry &&
1:04:18 PM:   python -m poetry &&
1:04:18 PM:   poetry config virtualenvs.in-project true &&
1:04:18 PM:   poetry install -v &&
1:04:18 PM:   mkdocs build
1:04:18 PM: ​​
1:04:18 PM:   Resolved config
1:04:18 PM:   build:
1:04:18 PM:     command: |
1:04:18 PM:       pip3 install -q poetry &&
1:04:18 PM:       python -m poetry &&
1:04:18 PM:       poetry config virtualenvs.in-project true &&
1:04:18 PM:       poetry install -v &&
1:04:18 PM:       mkdocs build
1:04:18 PM:     commandOrigin: config
1:04:18 PM:     environment:
1:04:18 PM:       - XXX
1:04:18 PM:     publish: /opt/build/repo/site
1:04:18 PM:     publishOrigin: config
1:04:18 PM:   redirectsOrigin: config
1:04:18 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
1:04:18 PM: Failing build: Failed to build site
1:04:18 PM: Finished processing build request in 35.138s

Would love an update on this issue. Builds are still failing 2 days laters

Adding more threads about the same topic is never a good idea. You made us read through an extra thread with the same level of detail about the same issue - which basically slowed us down.

In any case, I’ve passed this to the devs and asked them to take a look.

Appreciated, and apologies for the extra work.

Solved: This was due to a dependency (Pillow) that contained security vulnerabilities.

Pillow = "^10.0.0" in my pyproject.toml poetry config to be precise.It’s used for mkdocs’ image processing for social cards.

I fixed this by removing poetry from my build/deploy process and just using requirements.txt to manage dependencies. Even then I only caught these errors after pushing my requirements.txt file to my repository, where GitHub flagged the vulnerabilities prompting me to upgrade the dependency from version 10 → 11.

My poetry install command was set to verbose ( poetry install -v &&) but I guess this doesn’t show vulnerability errors/warnings.