{"record":{"id":"2724c030370e3a45","repo":"neoclide/coc.nvim","slug":"unsupported-module-type-ext-for-cachekey","errorCode":null,"errorMessage":"Unsupported module type \"${ext}\" for ${cacheKey}","messagePattern":"Unsupported module type \"(.+?)\" for (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/extension/loader.ts","lineNumber":255,"sourceCode":"    if (request === 'coc.nvim') return this.runtime.api\n    if (this.isBuiltin(request)) return this.loadBuiltin(request)\n    let resolved = resolveExtensionModule(this.runtime, request, parent.filename, 'require')\n    if (resolved.type === 'file' && resolved.format === 'module') {\n      throw requireESMError(resolved.filename)\n    }\n    // Builtins and coc.nvim are handled above, so resolution always yields a\n    // file module here.\n    return this.load((resolved as any).filename, parent)\n  }\n\n  public load(filename: string, parent?: ExtensionCommonJSModule, isMain = false): unknown {\n    const cacheKey = this.normalizeFilename(filename)\n    const ext = path.extname(cacheKey).toLowerCase()\n    if (ext === '.json') return this.loadJson(cacheKey, parent)\n    if (ext === '.node') return this.loadNative(cacheKey, parent)\n    if (ext === '.js' || ext === '.cjs' || ext === '') return this.loadJavaScript(cacheKey, parent)\n    if (ext === '.mjs') throw requireESMError(cacheKey)\n    throw new Error(`Unsupported module type \"${ext}\" for ${cacheKey}`)\n  }\n\n  /**\n   * Load a native addon outside the VM. The addon is dlopen'd by Node and its\n   * exports are cached in the runtime module cache.\n   */\n  public loadNative(filename: string, parent?: ExtensionCommonJSModule): unknown {\n    const cacheKey = this.normalizeFilename(filename)\n    const cached = this.runtime.cjsModules.get(cacheKey)\n    if (cached) return cached.exports\n    const nodeModule = new Module(cacheKey)\n    nodeModule.filename = cacheKey\n    nodeModule.paths = Module._nodeModulePaths(path.dirname(cacheKey))\n    const nativeLoad = Module._extensions && Module._extensions['.node']\n    if (typeof nativeLoad !== 'function') {\n      throw new Error(`Unsupported native addon: ${cacheKey}`)\n    }\n    nativeLoad(nodeModule, cacheKey)","sourceCodeStart":237,"sourceCodeEnd":273,"githubUrl":"https://github.com/neoclide/coc.nvim/blob/50e974d9692461a69147d5cab146a8d3e439abe4/src/extension/loader.ts#L237-L273","documentation":" thrown by the sandbox module loader's load() when a module's file extension isn't one it supports (.json, .node, .js, .cjs, empty, .mjs). ESM (.mjs) gets a dedicated error; anything else is outright unsupported in the sandboxed require implementation.","triggerScenarios":"require('.../.ts') or .tsx/.jsx/.wasm/.mts files from an extension; require resolving a file with an unusual extension; tools trying to load WebAssembly via require.","commonSituations":"Extensions importing TypeScript source directly instead of compiled JS; monorepo code resolving uncompiled assets; attempted require of .wasm or template files.","solutions":["Compile the module to .js/.cjs before requiring it in the extension.","Rename/emit the file with a supported extension (.js, .cjs, .json).","Use the ESM entry (.mjs) only if your loader path supports it — otherwise bundle to CJS.","Don't require non-code assets via require; read them with fs and parse manually (e.g. .wasm via WebAssembly API if exposed)."],"exampleFix":"// before\nconst helper = require('./helper.ts')\n// after (compile first)\nconst helper = require('./helper.js')","handlingStrategy":"validation","validationCode":"const ext = path.extname(modulePath).toLowerCase()\nconst supported = ['.json', '.node', '.js', '.cjs', '.mjs', '']\nif (!supported.includes(ext)) throw new Error(`unsupported ext ${ext}; compile to .js first`)","typeGuard":"function hasSupportedExt(f) { return ['', '.js', '.cjs', '.json', '.node', '.mjs'].includes(path.extname(f).toLowerCase()) }","tryCatchPattern":"try { const m = sandboxRequire(p) } catch (e) { if (e.message.startsWith('Unsupported module type')) { /* bundle/compile the module, then retry */ } else { throw e } }","preventionTips":["Ship extensions as compiled .js/.cjs, never raw .ts","Don't require() non-code assets; read them with fs","Pre-bundle wasm/native code paths"],"tags":["module-loader","sandbox","require","file-extension"],"backgroundTag":"unsupported-module-type","analyzedSha":"50e974d9692461a69147d5cab146a8d3e439abe4","analyzedAt":"2026-08-31T11:17:23.966Z","schemaVersion":2},"datasetVersion":"2026-09-01T08:17:40.651Z"}