microsoft/typescript-go · error · Error
forRelease requires setPrerelease unless nativePreviewReleas
Error message
forRelease requires setPrerelease unless nativePreviewReleaseVersion is hardcoded and VSIX production is disabled
What it means
Same nil-project condition as the plain lookup, but on the auto-import path: Session.GetLanguageServiceWithAutoImports clones the snapshot with cloneWithAutoImports for the URI, then calls GetDefaultProject on the clone. If the file belongs to no project, the freshly cloned snapshot is explicitly Deref'd (its initial ref of 1 is released to avoid a leak) and the error is returned. This is the entry point used for completions that need auto-import resolution, so it typically surfaces mid-completion-request.
Source
Thrown at Herebyfile.mjs:99
// We can't use parseArgs' strict mode as it errors on hereby's --tasks flag.
/**
* @typedef {{ [K in keyof typeof rawOptions as {} extends Record<K, 1> ? never : K]: typeof rawOptions[K] }} Options
*/
const options = /** @type {Options} */ (rawOptions);
// Native release branches can edit these constants to publish a fixed stable version.
// Main publishes prerelease builds of the TypeScript package.
const nativePreviewReleaseProfile = /** @type {"native-preview" | "typescript"} */ ("typescript");
const nativePreviewReleaseVersion = /** @type {string | undefined} */ (undefined);
const produceNativePreviewVsix = /** @type {boolean} */ (false);
const produceTypeScriptNightlyVsix = /** @type {boolean} */ (true);
const usePublishedPlatformPackagesForVsix = /** @type {boolean} */ (false);
const produceAnyVsix = produceNativePreviewVsix || produceTypeScriptNightlyVsix;
const publishAsTypescript = nativePreviewReleaseProfile === "typescript";
if (options.forRelease && !options.setPrerelease && (!nativePreviewReleaseVersion || produceAnyVsix)) {
throw new Error("forRelease requires setPrerelease unless nativePreviewReleaseVersion is hardcoded and VSIX production is disabled");
}
if (usePublishedPlatformPackagesForVsix && !publishAsTypescript) {
throw new Error("usePublishedPlatformPackagesForVsix requires nativePreviewReleaseProfile to be 'typescript'");
}
const defaultGoBuildTags = [
...(options.noembed ? ["noembed"] : []),
];
/**
* @param {...string} extra
* @returns {string[]}
*/
function goBuildTags(...extra) {
const tags = new Set(defaultGoBuildTags.concat(extra));
return tags.size ? [`-tags=${[...tags].join(",")}`] : [];
}
View on GitHub (pinned to 1bcfa18d79)
Solutions
- Ensure the document is part of a project before requesting completions: open it via didOpen and/or include it in tsconfig.json.
- If the tsconfig was edited, wait for the configuration-change reload to be adopted (the clone is based on baseSnapshot; stale snapshots keep the old project set).
- Guard callers: check snapshot.GetProjectsContainingFile(uri) (snapshot.go:86) and skip/degrade the auto-import path instead of failing the whole request.
- Verify path/case normalization of the URI matches the host filesystem to avoid a false miss in GetDefaultProject.
Example fix
// before
ls, err := session.GetLanguageServiceWithAutoImports(ctx, snapshot, uri)
if err != nil { return err }
// after: degrade gracefully for out-of-project files
if len(snapshot.GetProjectsContainingFile(uri)) == 0 {
ls, err = session.GetLanguageService(ctx, uri) // or return empty completions
if err != nil { return err }
} else {
ls, err = session.GetLanguageServiceWithAutoImports(ctx, snapshot, uri)
if err != nil { return err }
} Defensive patterns
Strategy: validation
Validate before calling
// auto-import path only works for files already inside a project
if len(baseSnapshot.GetProjectsContainingFile(uri)) == 0 {
// skip auto-import enrichment; fall back to plain service or empty completions
return session.GetLanguageService(ctx, uri)
} Type guard
func canAutoImport(snap *project.Snapshot, uri lsproto.DocumentUri) bool {
return snap.GetDefaultProject(uri) != nil // clone preserves the project set
} Try / catch
ls, err := session.GetLanguageServiceWithAutoImports(ctx, snap, uri)
if err != nil {
if strings.Contains(err.Error(), "no project found for URI") {
// completion can continue without auto-imports
return basicCompletions(ctx, uri)
}
return nil, err
} Prevention
- Ensure didOpen preceded the completion request.
- After tsconfig edits, wait for the new snapshot to be adopted before requesting completions.
- Treat out-of-project files as a normal completion edge case, not an error path.
When it happens
Trigger: Triggering a completion (or other auto-import-enabled request) in a document that no project in the cloned snapshot contains: never opened via didOpen, excluded from every tsconfig, outside the workspace root, or a URI whose normalized path does not match the ProjectCollection keys. Because cloneWithAutoImports only enriches import resolution, it never creates a project for an unknown file — nil in implies nil out.
Common situations: Completing in a scratch/untitled buffer; completing in a file recently created on disk but not yet added to the project graph or reloaded after tsconfig edits; single-file sessions where no inferred project backs the file; VS Code multi-root workspaces where one root's tsconfig excludes the requested file.
Related errors
- Invalid value for ${name}: ${value}
- completion item data is nil
- Language client is not initialized
- Unexpected number of arguments.
- missing required properties: %s
AI-assisted analysis of microsoft/typescript-go@1bcfa18d79 (2026-08-16).
Data as JSON: /api/errors/26217d9af8b179e9.
Report an issue: GitHub.