Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@parcel/transformer-elm can't resolve Elm binary for for linux_arm64 arch #10112

Open
Confidenceman02 opened this issue Mar 15, 2025 · 0 comments

Comments

@Confidenceman02
Copy link

Confidenceman02 commented Mar 15, 2025

🐛 bug report

@parcel/transformer-elm does not resolve a compiler for linux_arm64 architectures, and fails when building projects.

🤔 Expected Behavior

Can resolve the correct compiler for linux_arm64 architectures.

😯 Current Behavior

Returns a failure message which has nothing to do with the underlying issue when running parcel in any configuration that uses @parcel/transformer-elm to compile Elm programs.

The actual message that shows up in the console is a JSON parsing error and not indicative of the actual underlying issue:

No number after minus sign in JSON at position 1 (line 1 column 2)

This comes from the following line in the code found in ElmTransformer.js:

    try {
      code = await compileToString(_nodeElmCompiler().default, elmBinary, sources, compilerConfig);
    } catch (e) {
      let compilerJson = e.message.split('\n')[1];
      let compilerDiagnostics = JSON.parse(compilerJson); // *<--- Error that is surfaced

The error that we care however is the the e variable. Printing that out shows that actual problem:

-- ERROR -----------------------------------------------------------------------

I am detecting that your computer (linux_arm64) may not be compatible with any
of the official pre-built binaries.

I recommend against using the npm installer for your situation. Check out the
alternative installers at https://github.com/elm/compiler/releases/tag/0.19.1
to see if there is something that will work better for you.

From there I recommend asking for guidance on Slack or Discourse to find someone
who can help with your specific situation.

--------------------------------------------------------------------------------

Clearly this output is not JSON and thus the reason for the JSON parsing error.

💁 Possible Solution

It is best practice to install the elm binary directly on your system, the official approach from the Elm docs is to use a command like the following:

# Elm
RUN curl -sS -L -o elm.gz https://github.com/elm/compiler/releases/download/0.19.1/binary-for-linux-64-bit.gz \
    && gunzip elm.gz \
    && chmod +x elm \
    && mv elm /usr/local/bin

Quite often, this is how folks install and use Elm. The elm binary that is used via @parcel/transformer-elm is a convenience but mostly redundant in systems where Elm already is setup. Certainly in this case.

The official setup as demonstrated above already produces a compatible Elm binary to use in linux_arm64 environments, such as linux containers run on Mac's.

It would make sense to be able to use an env variable that when present would be used as the compiler binary that @parcel/transformer-elm resolves.

It would work similar to the PARCEL_ELM_NO_DEBUG flag functionality that currently exists.

In the resolveLocalElmBinary function, implemented naively:

function resolveLocalElmBinary(options) {
  try {
    if (options.env.PARCEL_ELM_BINARY) return options.env.PARCEL_ELM_BINARY // <-- PROPOSED
    let result = require.resolve('elm/package.json');
    // $FlowFixMe
    let pkg = require('elm/package.json');
    let bin = nullthrows(pkg.bin); // <-- current
    return path.join(
      path.dirname(result),
      typeof bin === 'string' ? bin : bin.elm,
    );
  } catch (_) {
    return null;
  }
}

🔦 Context

It took a lot of debugging to find the underlying issue I was facing due to the actual cause that was being overshadowed by a JSON parsing error.

💻 Code Sample

For the following elm programs

module Main exposing (main)

import Html exposing (text)

main =
    text "Hello, Parcel!"

Run the following command:

pnpm parcel build ./src/Main.elm --no-cache

🌍 Your Environment

Software Version(s)
Parcel 2.13.2
Node 22.14.0
pnpm 10.5.1
Operating System Darwin
Docker 27.5.1
Container python:3.12.9-slim-bookworm
Container arch linux_arm64
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant