laurent22/joplin · warning · Error

Cannot decode resource with encoding: ${dataEncoding}

Error message

Cannot decode resource with encoding: ${dataEncoding}

What it means

Thrown by the ENEX resource decoder when a <data> element's encoding attribute is present but not 'base64'. The importer only implements base64 decoding; the ENEX DTD defaults encoding to base64, so any other value (e.g. 'text', custom encodings) is unsupported and rejected rather than mis-decoded.

Source

Thrown at packages/lib/import-enex.ts:159

		resource.size = 0;
		resource.dataFilePath = `${Setting.value('tempDir')}/${resource.id}.empty`;
		await shim.fsDriver().writeFile(resource.dataFilePath, '');
	};

	if (!resource.hasData) {
		// Some resources have no data, go figure, so we need a special case for this.
		await handleNoDataResource(resource, true);
	} else {
		// If encoding is not specified, it defaults to base64.
		// Source: enex.dtd: <!ATTLIST data encoding (base64) "base64">
		const dataEncoding = resource.dataEncoding ? resource.dataEncoding : 'base64';

		if (dataEncoding === 'base64') {
			const decodedFilePath = `${resource.dataFilePath}.decoded`;
			await decodeBase64File(resource.dataFilePath, decodedFilePath);
			resource.dataFilePath = decodedFilePath;
		} else if (dataEncoding) {
			throw new Error(`Cannot decode resource with encoding: ${dataEncoding}`);
		}

		const stats = await shim.fsDriver().stat(resource.dataFilePath);
		resource.size = stats.size;

		if (!resource.id) {
			// If no resource ID is present, the resource ID is actually the MD5
			// of the data. This ID will match the "hash" attribute of the
			// corresponding <en-media> tag. resourceId = md5(decodedData);
			resource.id = await shim.fsDriver().md5File(resource.dataFilePath);
		}

		if (!resource.id || !resource.size) {
			// Don't throw an error because it happens semi-frequently,
			// especially on notes that comes from the Evernote Web Clipper and
			// we can't do anything about it. Previously we would throw the
			// error "This resource was not added because it has no ID or no
			// content".

View on GitHub (pinned to 2654b33620)

Solutions

  1. Re-export from the official Evernote client, which always uses base64.
  2. Pre-process the ENEX: convert the resource data to base64 and set encoding="base64" (or drop the attribute, since base64 is the default).
  3. If you control the importer, add a decoder branch for the encountered encoding.
  4. Strip the offending resource from the ENEX if it's non-essential.

Example fix

// before
if (dataEncoding === 'base64') { /* decode */ }
else if (dataEncoding) { throw new Error(`Cannot decode resource with encoding: ${dataEncoding}`); }
// after - fall back to treating unencoded content as raw text/binary
if (dataEncoding === 'base64') { await decodeBase64File(...); }
else if (dataEncoding === 'none' || dataEncoding === 'text') { resource.dataFilePath = rawPath; }
else { throw new Error(`Unsupported resource encoding: ${dataEncoding}`); }
Defensive patterns

Strategy: validation

Validate before calling

if (resource.dataEncoding && resource.dataEncoding !== 'base64') {
  throw new Error(`Unsupported ENEX data encoding '${resource.dataEncoding}'; convert to base64 before import.`);
}

Type guard

function isSupportedEncoding(enc: string | undefined): boolean {
  return !enc || enc === 'base64';
}

Try / catch

try {
  await importEnexResource(resource);
} catch (e) {
  if (/Cannot decode resource with encoding/.test(e.message)) {
    // convert the resource data to base64 offline, then retry; or skip the resource
    logger.warn('Skipping resource with unsupported encoding:', e.message);
    return;
  }
  throw e;
}

Prevention

When it happens

Trigger: Importing an .enex whose resource <data encoding="..."> uses a non-base64 value — produced by a non-Evernote exporter, a modified ENEX, or a tool that emits a non-standard encoding attribute.

Common situations: Third-party note app exporting to ENEX with a different encoding; manually edited ENEX; corrupted export; an experimental/legacy Evernote format that used a non-base64 encoding.

Related errors


AI-assisted analysis of laurent22/joplin@2654b33620 (2026-08-12). Data as JSON: /api/errors/b4fa5e4b85a82028. Report an issue: GitHub.