transformers.js icon indicating copy to clipboard operation
transformers.js copied to clipboard

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

Open logancyang opened this issue 1 year ago • 5 comments

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 to use the huggingface transformers embeddings in my Obsidian plugin 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

// 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.<anonymous> (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:

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();
}

logancyang avatar Jan 19 '24 20:01 logancyang

console log your variable: var __dirname = RUNNING_LOCALLY ? import_path.default.dirname(import_path.default.dirname(import_url.default.fileURLToPath(import_meta.url))) : "./";

this __dirname not return string or URL instance, look like it return undefined

Plugin failure: copilot TypeError: The "path" argument must be of type string or an instance of URL. Received undefined

hiepxanh avatar Jan 23 '24 09:01 hiepxanh

@hiepxanh the stacktrace I posted shows Object.fileURLToPath got undefined as argument, so import_meta.url is undefined. A couple of lines above there's import_meta = {} so there's ofc no url. Not sure what to make of this.

logancyang avatar Jan 23 '24 19:01 logancyang

do you use ESM?

hiepxanh avatar Jan 24 '24 01:01 hiepxanh

do you use ESM?

Just confirmed with the Obsidian community, ESM is not an option right now, all Obsidian plugin must be CJS. I wonder what I can do here 🫠 Hopefully the good people here can find a workaround SCR-20240123-qnmg

logancyang avatar Jan 24 '24 02:01 logancyang

@logancyang you cannot do anything, I have to refactor my code to ESM and decided to give up and use API haha

hiepxanh avatar Jan 24 '24 06:01 hiepxanh