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 { ApiIndexer } from '../src/search/api-indexer.js';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,11 @@
|
|||||||
#!/usr/bin/env tsx
|
#!/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 { LanceDBIndexer, DocumentSource } from '../src/search/lancedb-indexer.js';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { fileURLToPath } from 'url';
|
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';
|
import { SourceCodeIndexer } from '../src/search/source-code-indexer.js';
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
|
|||||||
@ -58,13 +58,10 @@ export class LanceDBIndexer {
|
|||||||
console.log('Initializing LanceDB connection...');
|
console.log('Initializing LanceDB connection...');
|
||||||
this.db = await connect(this.dbPath);
|
this.db = await connect(this.dbPath);
|
||||||
|
|
||||||
// Configure ONNX Runtime backend based on environment variable
|
// Log which backend is being used
|
||||||
// TRANSFORMERS_BACKEND=wasm for Alpine Linux (musl libc)
|
const backend = process.env.ONNXRUNTIME_BACKEND;
|
||||||
// Default: native ONNX Runtime (faster, requires glibc)
|
if (backend === 'wasm') {
|
||||||
const backend = process.env.TRANSFORMERS_BACKEND;
|
|
||||||
if (backend === 'wasm' || backend === 'onnxruntime-web') {
|
|
||||||
console.log('Using WASM backend for Transformers.js (Alpine/musl compatibility mode)');
|
console.log('Using WASM backend for Transformers.js (Alpine/musl compatibility mode)');
|
||||||
process.env.ONNXRUNTIME_BACKEND = 'wasm';
|
|
||||||
} else {
|
} else {
|
||||||
console.log('Using native ONNX Runtime backend (glibc required)');
|
console.log('Using native ONNX Runtime backend (glibc required)');
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user