Fix WASM backend configuration for Alpine Linux
Set ONNXRUNTIME_BACKEND environment variable before module imports to prevent onnxruntime-node from loading. The environment variable must be set before @xenova/transformers is imported. Updated all index scripts (index-docs, index-api, index-source) to configure the backend at the script entry point. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
adff6c1ec5
commit
dfccbf110a
@ -1,3 +1,9 @@
|
||||
// MUST set environment variable before any imports that use @xenova/transformers
|
||||
// This prevents onnxruntime-node from being loaded on Alpine Linux (musl libc)
|
||||
if (process.env.TRANSFORMERS_BACKEND === 'wasm' || process.env.TRANSFORMERS_BACKEND === 'onnxruntime-web') {
|
||||
process.env.ONNXRUNTIME_BACKEND = 'wasm';
|
||||
}
|
||||
|
||||
import { ApiIndexer } from '../src/search/api-indexer.js';
|
||||
import path from 'path';
|
||||
|
||||
|
||||
@ -1,5 +1,11 @@
|
||||
#!/usr/bin/env tsx
|
||||
|
||||
// MUST set environment variable before any imports that use @xenova/transformers
|
||||
// This prevents onnxruntime-node from being loaded on Alpine Linux (musl libc)
|
||||
if (process.env.TRANSFORMERS_BACKEND === 'wasm' || process.env.TRANSFORMERS_BACKEND === 'onnxruntime-web') {
|
||||
process.env.ONNXRUNTIME_BACKEND = 'wasm';
|
||||
}
|
||||
|
||||
import { LanceDBIndexer, DocumentSource } from '../src/search/lancedb-indexer.js';
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// MUST set environment variable before any imports that use @xenova/transformers
|
||||
// This prevents onnxruntime-node from being loaded on Alpine Linux (musl libc)
|
||||
if (process.env.TRANSFORMERS_BACKEND === 'wasm' || process.env.TRANSFORMERS_BACKEND === 'onnxruntime-web') {
|
||||
process.env.ONNXRUNTIME_BACKEND = 'wasm';
|
||||
}
|
||||
|
||||
import { SourceCodeIndexer } from '../src/search/source-code-indexer.js';
|
||||
|
||||
async function main() {
|
||||
|
||||
@ -58,13 +58,10 @@ export class LanceDBIndexer {
|
||||
console.log('Initializing LanceDB connection...');
|
||||
this.db = await connect(this.dbPath);
|
||||
|
||||
// Configure ONNX Runtime backend based on environment variable
|
||||
// TRANSFORMERS_BACKEND=wasm for Alpine Linux (musl libc)
|
||||
// Default: native ONNX Runtime (faster, requires glibc)
|
||||
const backend = process.env.TRANSFORMERS_BACKEND;
|
||||
if (backend === 'wasm' || backend === 'onnxruntime-web') {
|
||||
// Log which backend is being used
|
||||
const backend = process.env.ONNXRUNTIME_BACKEND;
|
||||
if (backend === 'wasm') {
|
||||
console.log('Using WASM backend for Transformers.js (Alpine/musl compatibility mode)');
|
||||
process.env.ONNXRUNTIME_BACKEND = 'wasm';
|
||||
} else {
|
||||
console.log('Using native ONNX Runtime backend (glibc required)');
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user