{"id":"4f65b072257b6cfa","repo":"evanw/esbuild","slug":"the-input-to-transform-must-be-a-string-or-a-uin","errorCode":null,"errorMessage":"The input to \"transform\" must be a string or a Uint8Array","messagePattern":"The input to \"transform\" must be a string or a Uint8Array","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/shared/common.ts","lineNumber":708,"sourceCode":"    // Ideally the \"transform()\" API would be faster than calling \"build()\"\n    // since it doesn't need to touch the file system. However, performance\n    // measurements with large files on macOS indicate that sending the data\n    // over the stdio pipe can be 2x slower than just using a temporary file.\n    //\n    // This appears to be an OS limitation. Both the JavaScript and Go code\n    // are using large buffers but the pipe only writes data in 8kb chunks.\n    // An investigation seems to indicate that this number is hard-coded into\n    // the OS source code. Presumably files are faster because the OS uses\n    // a larger chunk size, or maybe even reads everything in one syscall.\n    //\n    // The cross-over size where this starts to be faster is around 1mb on\n    // my machine. In that case, this code tries to use a temporary file if\n    // possible but falls back to sending the data over the stdio pipe if\n    // that doesn't work.\n    let start = (inputPath: string | null) => {\n      try {\n        if (typeof input !== 'string' && !(input instanceof Uint8Array))\n          throw new Error('The input to \"transform\" must be a string or a Uint8Array')\n        let {\n          flags,\n          mangleCache,\n        } = flagsForTransformOptions(callName, options, isTTY, transformLogLevelDefault)\n        let request: protocol.TransformRequest = {\n          command: 'transform',\n          flags,\n          inputFS: inputPath !== null,\n          input: inputPath !== null ? protocol.encodeUTF8(inputPath)\n            : typeof input === 'string' ? protocol.encodeUTF8(input)\n              : input,\n        }\n        if (mangleCache) request.mangleCache = mangleCache\n        sendRequest<protocol.TransformRequest, protocol.TransformResponse>(refs, request, (error, response) => {\n          if (error) return callback(new Error(error), null)\n          let errors = replaceDetailsInMessages(response!.errors, details)\n          let warnings = replaceDetailsInMessages(response!.warnings, details)\n          let outstanding = 1","sourceCodeStart":690,"sourceCodeEnd":726,"githubUrl":"https://github.com/evanw/esbuild/blob/6ff1d8b0d8c134e867a397eef39702a223ebef9e/lib/shared/common.ts#L690-L726","documentation":"Error \"The input to \"transform\" must be a string or a Uint8Array\" thrown in evanw/esbuild.","triggerScenarios":"Thrown at lib/shared/common.ts:708 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass a string or Uint8Array as the first argument to \"transform\"","Read file contents yourself and pass the string/bytes instead of a path or other type"],"exampleFix":"const result = await esbuild.transform('let x: number = 1', { loader: 'ts' });","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"6ff1d8b0d8c134e867a397eef39702a223ebef9e","analyzedAt":"2026-08-03T19:42:38.433Z","schemaVersion":2}