{"record":{"id":"057d5efa66326426","repo":"pulumi/pulumi","slug":"cannot-determine-resource-type-source-file-not-fo","errorCode":null,"errorMessage":"Cannot determine resource type: source file not found for declaration of '${symbol.name}' for ${this.formatErrorContext(context)}","messagePattern":"Cannot determine resource type: source file not found for declaration of '(.+?)' for (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"sdk/nodejs/provider/experimental/analyzer.ts","lineNumber":976,"sourceCode":"        const symbol = type.getSymbol();\n        if (!symbol) {\n            throw new Error(\n                `Cannot determine resource type: source (symbol) not found for type '${this.checker.typeToString(type)}' for ${this.formatErrorContext(context)}`,\n            );\n        }\n\n        // Try to find the declaration of the class\n        const declaration = symbol.declarations?.[0];\n        if (!declaration) {\n            throw new Error(\n                `Cannot determine resource type: source (declaration) not found for symbol '${symbol.name}' for ${this.formatErrorContext(context)}`,\n            );\n        }\n\n        // Find its declaration source file.\n        const sourceFile = declaration.getSourceFile();\n        if (!sourceFile) {\n            throw new Error(\n                `Cannot determine resource type: source file not found for declaration of '${symbol.name}' for ${this.formatErrorContext(context)}`,\n            );\n        }\n\n        // Find the actual implementation file - use the TypeScript file directly if it's not a .d.ts file\n        let implPath = sourceFile.fileName;\n        if (implPath.endsWith(\".d.ts\")) {\n            // For declaration files, look for the corresponding .js file\n            implPath = implPath.replace(/\\.d\\.ts$/, \".js\");\n        }\n\n        if (!ts.sys.fileExists(implPath)) {\n            throw new Error(\n                `Cannot determine resource type: source file not found at '${implPath}' for '${symbol.name}' for ${this.formatErrorContext(context)}`,\n            );\n        }\n\n        // Load the module.","sourceCodeStart":958,"sourceCodeEnd":994,"githubUrl":"https://github.com/pulumi/pulumi/blob/793f7b2e160db4321fb7fb6b0607461e01cb251e/sdk/nodejs/provider/experimental/analyzer.ts#L958-L994","documentation":"The analyzer calls `declaration.getSourceFile()` to locate the file containing the resource class. If the TypeScript AST returns no source file for the declaration (rare, e.g. synthesized declarations or transient symbols from transformed programs), the implementation path cannot be computed and it throws naming the symbol.","triggerScenarios":"Analyzing types whose declarations originate from synthesized/virtual source files — e.g. types produced by TS transformers, in-memory programs, or declarations injected by bundler plugins rather than real files on disk.","commonSituations":"Build pipelines using custom TypeScript transformers or virtual module plugins; analyzing inside tools that create program instances from memory rather than disk.","solutions":["Ensure the resource class is declared in a real `.ts` file included in the program's root files.","Remove or bypass custom transformers/virtual modules for the provider package being analyzed.","Check the tsconfig `include`/`rootDir` settings so the class's file is part of the analyzed program."],"exampleFix":"// before (virtual module declared by a plugin)\ndeclare module \"virtual:resource\" { export class Widget {} }\n\n// after (real file)\n// src/widget.ts\nexport class Widget extends pulumi.ComponentResource {}","handlingStrategy":"validation","validationCode":"// Check the declaration is anchored to a real source file:\nconst decl = symbol.declarations?.[0];\nif (!decl?.getSourceFile?.() || decl.getSourceFile().fileName.includes(\"virtual\")) {\n  throw new Error(\"resource class must be declared in a real on-disk .ts file\");\n}","typeGuard":"function hasRealSourceFile(decl: ts.Declaration | undefined): boolean {\n  const f = decl?.getSourceFile?.();\n  return !!f && !f.fileName.startsWith(\"typescript/lib\") && ts.sys.fileExists(f.fileName);\n}","tryCatchPattern":"try {\n  resolveResourceType(propType);\n} catch (e) {\n  if (String(e.message).includes(\"source file not found for declaration\")) {\n    console.error(`${e.message} — move the class into a real .ts file in the analyzed program`);\n  } else { throw e; }\n}","preventionTips":["Do not declare resources inside virtual modules or transformer-generated code.","Keep resource classes in ordinary `.ts` files included by tsconfig.","Avoid running the analyzer inside in-memory/transformed TS programs.","Keep the provider package's program plain `tsc` output."],"tags":["typescript","resource-reference","source-file"],"backgroundTag":"cannot-determine-resource-type","analyzedSha":"793f7b2e160db4321fb7fb6b0607461e01cb251e","analyzedAt":"2026-08-31T09:36:43.099Z","schemaVersion":2},"datasetVersion":"2026-09-01T08:17:40.651Z"}