swc-project/swc · error

failed to parse inline source map: not base64: {url:?}

Error message

failed to parse inline source map: not base64: {url:?}

What it means

While reading an inline input source map, swc parsed the `sourceMappingURL=data:...` URL successfully but its path lacks the `base64,` marker, so there is no base64 payload to decode (crates/swc/src/lib.rs). SWC only supports the standard base64-encoded inline form, `data:application/json;base64,...`. A malformed URL would fail earlier with a different message ('failed to parse inline source map url').

Source

Thrown at crates/swc/src/lib.rs:452

        &self,
        fm: &SourceFile,
        input_src_map: &InputSourceMap,
        comments: &[Comment],
        is_default: bool,
    ) -> Result<Option<sourcemap::SourceMap>, Error> {
        self.run(|| -> Result<_, Error> {
            let name = &fm.name;

            let read_inline_sourcemap =
                |data_url: &str| -> Result<Option<sourcemap::SourceMap>, Error> {
                    let url = Url::parse(data_url).with_context(|| {
                        format!("failed to parse inline source map url\n{data_url}")
                    })?;

                    let idx = match url.path().find("base64,") {
                        Some(v) => v,
                        None => {
                            bail!("failed to parse inline source map: not base64: {url:?}")
                        }
                    };

                    let content = url.path()[idx + "base64,".len()..].trim();

                    let res = BASE64_STANDARD
                        .decode(content.as_bytes())
                        .context("failed to decode base64-encoded source map")?;

                    Ok(Some(sourcemap::SourceMap::from_slice(&res).context(
                        "failed to read input source map from inlined base64 encoded string",
                    )?))
                };

            let read_file_sourcemap =
                |data_url: Option<&str>| -> Result<Option<sourcemap::SourceMap>, Error> {
                    match &**name {
                        FileName::Real(filename) => {

View on GitHub (pinned to 5176682b65)

Solutions

  1. Re-emit the inline map base64-encoded: `//# sourceMappingURL=data:application/json;base64,` + base64 of the map JSON
  2. Or move the map to an external file and reference `//# sourceMappingURL=index.js.map`
  3. If the input map is unneeded, delete the sourceMappingURL comment or set swc options to skip reading input maps

Example fix

// before
//# sourceMappingURL=data:application/json,{"version":3,...}
// after
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMifQ==
Defensive patterns

Strategy: validation

Validate before calling

// JavaScript - check the sourceMappingURL is base64 before compiling
function assertInlineMapIsBase64(source) {
  const m = source.match(/\/\/[#@]\s*sourceMappingURL=data:([^,]*)/);
  if (m && !m[1].includes('base64')) {
    throw new Error('sourceMappingURL data URI must be base64-encoded');
  }
}

Prevention

When it happens

Trigger: A compiled input file whose last line is `//# sourceMappingURL=data:application/json;charset=utf-8,{...raw JSON...}` (URI-encoded, not base64) or any data-URL map emitted without base64. Read during process_js_file/get_orig_src_map when input source maps are enabled.

Common situations: Hand-authored sourceMappingURL comments; tools/minifiers emitting non-standard non-base64 data URIs; pasting raw sourcemap JSON into the comment; concatenated bundle artifacts with mangled comments.

Understand the failure class

Related errors


AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17). Data as JSON: /api/errors/38a870e88f0b087f. Report an issue: GitHub.