dillonkearns / elm-pages

Hybrid Elm framework with full-stack and static routes.
https://elm-pages.com
BSD 3-Clause "New" or "Revised" License
653 stars 97 forks source link

Build Failure on Netlify with new elm-pages project #357

Open EvanPiro opened 1 year ago

EvanPiro commented 1 year ago

I'm receiving the following error when I run a deployment via netlify on a clean elm-pages project. It does work on my local (x86_64-darwin). I'm digging into this but I wanted to post this issue in case there's an obvious fix to someone more familiar with netlify.

12:48:30 PM: > build
12:48:30 PM: > elm-pages build
12:48:33 PM: Ran elm-review in 160ms
12:48:33 PM: -- PROBLEM BUILDING DEPENDENCIES -----------------------------------------------
12:48:33 PM: I ran into a compilation error when trying to build the following package:
12:48:33 PM:     elm/core 1.0.5
12:48:33 PM: This probably means it has package constraints that are too wide. It may be
12:48:33 PM: possible to tweak your elm.json to avoid the root problem as a stopgap. Head
12:48:33 PM: over to https://elm-lang.org/community to get help figuring out how to take this
12:48:33 PM: path!
12:48:33 PM: Note: To help with the root problem, please report this to the package author
12:48:33 PM: along with the following information:
12:48:33 PM: If you want to help out even more, try building the package locally. That should
12:48:33 PM: give you much more specific information about why this package is failing to
12:48:33 PM: build, which will in turn make it easier for the package author to fix it!
12:48:33 PM: Compilation failed.
12:48:33 PM: ​
12:48:33 PM:   "build.command" failed                                        
12:48:33 PM: ────────────────────────────────────────────────────────────────
12:48:33 PM: ​
12:48:33 PM:   Error message
12:48:33 PM:   Command failed with exit code 1: export ELM_HOME="$NETLIFY_BUILD_BASE/cache/elm" && npm install --no-optional && npm run build (https://ntl.fyi/exit-code-1)
12:48:33 PM: ​
12:48:33 PM:   Error location
12:48:33 PM:   In build.command from netlify.toml:
12:48:33 PM:   export ELM_HOME="$NETLIFY_BUILD_BASE/cache/elm" && npm install --no-optional && npm run build
12:48:33 PM: ​
12:48:33 PM:   Resolved config
12:48:33 PM:   build:
12:48:33 PM:     command: export ELM_HOME="$NETLIFY_BUILD_BASE/cache/elm" && npm install --no-optional && npm run build
12:48:33 PM:     commandOrigin: config
12:48:34 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
dillonkearns commented 1 year ago

Hello @EvanPiro, there's a thread here where we finally realized what was happening there:

https://discourse.elm-lang.org/t/problem-building-dependencies-error-in-pipeline-solved/8755

The issue occurs intermittently when the Elm compiler is running multiple instances in parallel. elm-pages is doing this to build the client bundle as well as the backend bundle (for resolving DataSources and rendering HTML for the pages in the build step).

I have a fix for this in the v3 beta, which will be going to a release candidate shortly. It might also make sense to do a hotfix for this issue in the v2 branch to avoid this problem before v3 is stable and while people migrate to v3.

dillonkearns commented 1 year ago

If you do a clear cache and rerun build in Netlify it can sometimes resolve this issue. It can take a few tries, though. I believe that once a good cache is present the issue doesn't get triggered again with that set of dependencies because the issue comes from a race condition when multiple instances of the Elm compiler are trying to install the same dependency at the same time.

EvanPiro commented 1 year ago

@dillonkearns 4th try did the trick.