gleam-lang/gleam · error · ErrorType

ErrorType::OptionNotSupportedForTarget

Error message

ErrorType::OptionNotSupportedForTarget { target, option: UnsupportedOption::NativeEndianness }

What it means

ErrorType::OptionNotSupportedForTarget with UnsupportedOption::NativeEndianness: the native endianness option (native) on a bit array segment is not supported when compiling to JavaScript, because JS has no native byte-order control.

Solutions

  1. Replace native with an explicit big or little endianness option
  2. Pick the byte order your wire format actually requires (usually big) instead of host-native
  3. Gate native-endianness code behind a module used only on the Erlang target

Example fix

// before
<<num:int-size(32)-native>>
// after
<<num:int-size(32)-big>>
Defensive patterns

Strategy: validation

Validate before calling

// Avoid `native` on the JavaScript target
fn native_endianness_ok(target: String) -> Bool {
  target != "javascript"
}

Prevention

When it happens

Trigger: Any bit array segment written with the 'native' endianness option (e.g. <<x:int-native>>) in code compiled for Target::JavaScript, whether in an expression or a pattern.

Common situations: Shared code written for Erlang that uses native byte order, then compiled for the browser/Node; protocol code that relied on host endianness for speed.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of gleam-lang/gleam@15b07c7830 (2026-09-14). Data as JSON: /api/errors/d42159491439aa21. Report an issue: GitHub.

Appendix: source

Thrown at compiler-core/src/bit_array.rs:160

                    categories.type_ = Some(option);
                }
            }

            Signed { .. } | Unsigned { .. } => {
                if let Some(previous) = categories.signed {
                    return err(
                        ErrorType::ConflictingSignednessOptions {
                            existing_signed: previous.label(),
                        },
                        option.location(),
                    );
                } else {
                    categories.signed = Some(option);
                }
            }

            Native { .. } if target == Target::JavaScript => {
                return err(
                    ErrorType::OptionNotSupportedForTarget {
                        target,
                        option: UnsupportedOption::NativeEndianness,
                    },
                    option.location(),
                );
            }

            Big { .. } | Little { .. } | Native { .. } => {
                if let Some(previous) = categories.endian {
                    return err(
                        ErrorType::ConflictingEndiannessOptions {
                            existing_endianness: previous.label(),
                        },
                        option.location(),
                    );
                } else {
                    categories.endian = Some(option);

View on GitHub (pinned to 15b07c7830)