Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
createLanguageService
✓ import { createLanguageService } from 'browser-basedpyright';
✗ const { createLanguageService } = require('browser-basedpyright');
This package is primarily consumed in browser ESM environments; CommonJS `require` is generally not supported for client-side usage.
createInMemoryLanguageServiceHost
✓ import { createInMemoryLanguageServiceHost } from 'browser-basedpyright';
✗ import createInMemoryLanguageServiceHost from 'browser-basedpyright/host';
A named export for creating an in-memory host, crucial for providing virtual file system capabilities to the language service.
LanguageService
✓ import type { LanguageService } from 'browser-basedpyright';
✗ import { LanguageService } from 'browser-basedpyright';
This is a TypeScript type/interface definition. It should be imported using `import type` to prevent bundling issues or runtime errors if not tree-shaken.
This example demonstrates how to initialize the `browser-basedpyright` language service in a browser environment, provide it with virtual Python code, and retrieve type diagnostics. It also shows how to update file content and re-evaluate diagnostics.
import { createLanguageService, createInMemoryLanguageServiceHost, type LanguageService } from 'browser-basedpyright';
// --- Setup the host for the language service ---
// This host simulates a file system and provides content for the language service.
const pythonCode = `
class MyClass:
def __init__(self, name: str):
self.name = name
def greet(self) -> str:
return f"Hello, {self.name}!"
def process_data(value: int):
# This should be flagged if 'value' is not an int or if 'value' is a str
if value == "test": # This will cause a pyright warning
print("Test string")
obj = MyClass("World")
print(obj.greet())
process_data(123)
process_data("hello") # Pyright should flag this as type error
`;
const virtualFilePath = '/src/main.py';
const host = createInMemoryLanguageServiceHost({
getOpenFileContents: (path: string) => {
if (path === virtualFilePath) {
return pythonCode;
}
return undefined; // Or throw error for unknown files
},
getWorkspaceFiles: () => [virtualFilePath],
getPythonVersion: () => '3.10',
getPyrightConfig: () => ({
reportMissingImports: "warning",
reportUnknownMemberType: "warning"
}),
});
// --- Initialize the language service ---
const service: LanguageService = createLanguageService(host);
// --- Get diagnostics for the file ---
async function getAndPrintDiagnostics() {
const diagnostics = await service.getDiagnostics(virtualFilePath);
console.log(`Diagnostics for ${virtualFilePath}:`);
if (diagnostics.length === 0) {
console.log("No issues found.");
} else {
diagnostics.forEach(d => {
console.log(` [${d.severity}] ${d.message} at line ${d.range.start.line + 1}, col ${d.range.start.character + 1}`);
});
}
}
getAndPrintDiagnostics();
// Example of updating content and re-checking
setTimeout(async () => {
const updatedCode = `
class AnotherClass:
def say_hi(self):
print("Hi!")
another_obj = AnotherClass()
another_obj.say_hi()
# Fix the previous error
def process_data_fixed(value: int):
if value == 1:
print("One")
process_data_fixed(42)
# process_data_fixed("oops") // This would still be an error if uncommented
`;
host.setOpenFileContents(virtualFilePath, updatedCode);
console.log("\n--- Updated code and re-checking ---");
await getAndPrintDiagnostics();
}, 2000);
Errors
Common errors & fixes
TypeError: createLanguageService is not a function
The `browser-basedpyright` package was either not correctly installed, an incorrect import path/syntax was used, or the problematic `v1.39.2` version was installed which contained no exports.
fixEnsure `browser-basedpyright` is installed and updated to `v1.39.3` or later. Verify the import statement: `import { createLanguageService } from 'browser-basedpyright';`. Pyright: Incompatible types in assignment (expression of type 'str' cannot be assigned to type 'int')
This is a Pyright diagnostic indicating a type mismatch in the Python code being analyzed. The language service correctly identified that a string value was provided where an integer was expected.
fixReview the Python code for type correctness. For example, change a call like `process_data("hello")` to `process_data(123)` if the parameter expects an integer. ReferenceError: SharedArrayBuffer is not defined
Web Workers, especially those utilizing shared memory features for performance (common in language servers), require specific Cross-Origin Isolation (COOP/COEP) headers to be served by the web server. Without these, `SharedArrayBuffer` might not be available in the worker context.
fixConfigure your web server to send `Cross-Origin-Opener-Policy: same-origin` and `Cross-Origin-Embedder-Policy: require-corp` HTTP response headers for the HTML page hosting the application and potentially for the worker script itself.
Audit
Dependencies
No dependency data recorded yet.