huggingface / huggingface/transformers.js

The "path" argument must be of type string or an instance of URL. Received undefined

Open
#526 5 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
JavaScript
Stars
16.3k
Forks
1.2k
Avg merge
6d 2h
Merged PRs (30d)
6

Description

### System Info

transformers.js version: 2.14.0
MacOS Sonoma 14.2.1
NodeJS: v19.8.1
React: v18.2.0

### Environment/Platform

- [ ] Website/web-app
- [ ] Browser extension
- [ ] Server-side (e.g., Node.js, Deno, Bun)
- [X] Desktop app (e.g., Electron)
- [X] Other (e.g., VSCode extension)

### Description

Hi I'm trying to follow this [instruction at LangchainJS](https://js.langchain.com/docs/integrations/text_embedding/transformers) to use the huggingface transformers embeddings in my Obsidian plugin [copilot](https://github.com/logancyang/obsidian-copilot), but am seeing an error regarding this package, not sure how to fix, any help is greatly appreciated! Let me know if anything else is needed to debug this.

### Reproduction

## Issue
```js
// node_modules/@xenova/transformers/src/env.js
var import_meta = {};
var { env: onnx_env } = ONNX;
var VERSION2 = "2.14.0";
var WEB_CACHE_AVAILABLE = typeof self !== "undefined" && "caches" in self;
var FS_AVAILABLE = !isEmpty(import_fs.default);
var PATH_AVAILABLE = !isEmpty(import_path.default);
var RUNNING_LOCALLY = FS_AVAILABLE && PATH_AVAILABLE;
var __dirname = RUNNING_LOCALLY ? import_path.default.dirname(import_path.default.dirname(import_url.default.fileURLToPath(import_meta.url))) : "./";

Error:
Plugin failure: copilot TypeError: The "path" argument must be of type string or an instance of URL. Received undefined
at __node_internal_captureLargerStackTrace (node:internal/errors:490:5)
at new NodeError (node:internal/errors:399:5)
at Object.fileURLToPath (node:internal/url:1491:11)
at anonymous (plugin:copilot:89293:110)
at e. (app.js:1:2026677)
at app.js:1:237258
at Object.next (app.js:1:237363)
at a (app.js:1:236081)
```

## Additional info
Obsidian uses esbuild and my config is:

```js
import builtins from "builtin-modules";
import esbuild from "esbuild";
import svgPlugin from "esbuild-plugin-svg";
import process from "process";
import wasmPlugin from "./wasmPlugin.mjs";

const banner =
`/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/
`;

const prod = (process.argv[2] === "production");

const context = await esbuild.context({
banner: {
js: banner,
},
entryPoints: ["src/main.ts"],
bundle: true,
external: [
"obsidian",
"electron",
"@codemirror/autocomplete",
"@codemirror/collab",
"@codemirror/commands",
"@codemirror/language",
"@codemirror/lint",
"@codemirror/search",
"@codemirror/state",
"@codemirror/view",
"@lezer/common",
"@lezer/highlight",
"@lezer/lr",
...builtins],
format: "cjs",
target: "es2020",
logLevel: "info",
sourcemap: prod ? false : "inline",
treeShaking: true,
outfile: "main.js",
plugins: [svgPlugin(), wasmPlugin],
});

if (prod) {
await context.rebuild();
process.exit(0);
} else {
await context.watch();
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.