{"record":{"id":"4357dea1952cb2c0","repo":"evanw/esbuild","slug":"must-specify-kind-when-calling-resolve","errorCode":null,"errorMessage":"Must specify \"kind\" when calling \"resolve\"","messagePattern":"Must specify \"kind\" when calling \"resolve\"","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/shared/common.ts","lineNumber":1268,"sourceCode":"        let resolveDir = getFlag(options, keys, 'resolveDir', mustBeString)\n        let kind = getFlag(options, keys, 'kind', mustBeString)\n        let pluginData = getFlag(options, keys, 'pluginData', canBeAnything)\n        let importAttributes = getFlag(options, keys, 'with', mustBeObject)\n        checkForInvalidFlags(options, keys, 'in resolve() call')\n\n        return new Promise((resolve, reject) => {\n          const request: protocol.ResolveRequest = {\n            command: 'resolve',\n            path,\n            key: buildKey,\n            pluginName: name,\n          }\n          if (pluginName != null) request.pluginName = pluginName\n          if (importer != null) request.importer = importer\n          if (namespace != null) request.namespace = namespace\n          if (resolveDir != null) request.resolveDir = resolveDir\n          if (kind != null) request.kind = kind\n          else throw new Error(`Must specify \"kind\" when calling \"resolve\"`)\n          if (pluginData != null) request.pluginData = details.store(pluginData)\n          if (importAttributes != null) request.with = sanitizeStringMap(importAttributes, 'with')\n\n          sendRequest<protocol.ResolveRequest, protocol.ResolveResponse>(refs, request, (error, response) => {\n            if (error !== null) reject(new Error(error))\n            else resolve({\n              errors: replaceDetailsInMessages(response!.errors, details),\n              warnings: replaceDetailsInMessages(response!.warnings, details),\n              path: response!.path,\n              external: response!.external,\n              sideEffects: response!.sideEffects,\n              namespace: response!.namespace,\n              suffix: response!.suffix,\n              pluginData: details.load(response!.pluginData),\n            })\n          })\n        })\n      }","sourceCodeStart":1250,"sourceCodeEnd":1286,"githubUrl":"https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/lib/shared/common.ts#L1250-L1286","documentation":"The plugin `resolve()` helper (lib/shared/common.ts:1268) requires a `kind` option that tells esbuild what kind of import is being resolved (e.g. `'import-statement'`, `'entry-point'`, `'require-call'`). The code reads `kind` with `mustBeString` and, if it is null/undefined, throws this error before sending the resolve request to the service.","triggerScenarios":"Calling `build.resolve(path)` or `build.resolve(path, {})` without a `kind` field inside a plugin callback.","commonSituations":"Assuming `kind` has a default; porting code from a different resolver API; passing `kind` as part of a nested object instead of the options top level.","solutions":["Always pass a `kind` string matching one of the documented ResolveKind values (e.g. `'import-statement'`, `'entry-point'`, `'require-call'`, `'dynamic-import'`).","Inside an onResolve hook, propagate the incoming `args.kind` so the value matches the real import context."],"exampleFix":"// before\nconst r = await build.resolve('./foo');\n// after\nconst r = await build.resolve('./foo', { kind: 'import-statement' });","handlingStrategy":"validation","validationCode":"const RESOLVE_KINDS = ['entry-point','import-statement','require-call','dynamic-import','require-resolve','import-rule','url-token'];\nfunction assertKind(kind: any) {\n  if (typeof kind !== 'string' || !RESOLVE_KINDS.includes(kind)) throw new Error('Invalid/missing resolve kind');\n}","typeGuard":"function isValidResolveKind(k: any): k is string {\n  return typeof k === 'string' && ['entry-point','import-statement','require-call','dynamic-import','require-resolve','import-rule','url-token'].includes(k);\n}","tryCatchPattern":null,"preventionTips":["Forward args.kind from onResolve handlers when re-resolving.","Keep a constant list of valid kinds near your plugin code."],"tags":["plugins","resolve","api-misuse","validation"],"backgroundTag":null,"analyzedSha":"f6058f8364fe7ab91ca57a83e02577ed74c9cae4","analyzedAt":"2026-08-09T18:37:22.223Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}