xenova / transformers.js

State-of-the-art Machine Learning for the web. Run 🤗 Transformers directly in your browser, with no need for a server!
https://huggingface.co/docs/transformers.js
Apache License 2.0
9.82k stars 579 forks source link

Could not read from file: D:\vite-project\node_modules\stream-browserify\web #742

Closed jzyzxx closed 1 month ago

jzyzxx commented 1 month ago

System Info

[ERROR] Could not read from file: D:\vite-project\node_modules\stream-browserify\web

    node_modules/@xenova/transformers/src/utils/hub.js:10:19:
      10 │ import stream from 'stream/web';
D:\vite-project\node_modules\esbuild\lib\main.js:1651
  let error = new Error(text);
              ^

Error: Build failed with 1 error:
node_modules/@xenova/transformers/src/utils/hub.js:10:19: ERROR: Could not read from file: D:\vite-project\node_modules\stream-browserify\web
    at failureErrorWithLog (D:\vite-project\node_modules\esbuild\lib\main.js:1651:15)
    at D:\vite-project\node_modules\esbuild\lib\main.js:1059:25
    at D:\vite-project\node_modules\esbuild\lib\main.js:1527:9
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  errors: [Getter/Setter],
  warnings: [Getter/Setter]
}

os:win11 node version:v21.6 npm config:

_auth = (protected)
access = null
all = false
allow-same-version = false
also = null
audit = true
audit-level = null
auth-type = "web"
before = null
bin-links = true
browser = null
ca = null
cache = "C:\\Users\\Administrator\\AppData\\Local\\npm-cache"
cache-max = null
cache-min = 0
cafile = null
call = ""
cert = null
cidr = null
color = true
commit-hooks = true
cpu = null
depth = null
description = true
dev = false
diff = []
diff-dst-prefix = "b/"
diff-ignore-all-space = false
diff-name-only = false
diff-no-prefix = false
diff-src-prefix = "a/"
diff-text = false
diff-unified = 3
dry-run = false
editor = "C:\\Windows\\notepad.exe"
engine-strict = false
fetch-retries = 2
fetch-retry-factor = 10
fetch-retry-maxtimeout = 60000
fetch-retry-mintimeout = 10000
fetch-timeout = 300000
force = false
foreground-scripts = false
format-package-lock = true
fund = true
git = "git"
git-tag-version = true
global = false
global-style = false
globalconfig = "D:\\nodejs\\etc\\npmrc"
heading = "npm"
; https-proxy = null ; overridden by user
if-present = false
ignore-scripts = false
include = []
include-staged = false
include-workspace-root = false
init-author-email = ""
init-author-name = ""
init-author-url = ""
init-license = "ISC"
init-module = "C:\\Users\\Administrator\\.npm-init.js"
init-version = "1.0.0"
init.author.email = ""
init.author.name = ""
init.author.url = ""
init.license = "ISC"
init.module = "C:\\Users\\Administrator\\.npm-init.js"
init.version = "1.0.0"
install-links = false
install-strategy = "hoisted"
json = false
key = null
legacy-bundling = false
legacy-peer-deps = false
link = false
local-address = null
location = "user"
lockfile-version = null
loglevel = "notice"
logs-dir = null
logs-max = 10
; long = false ; overridden by cli
maxsockets = 15
message = "%s"
node-options = null
noproxy = [""]
npm-version = "10.2.4"
offline = false
omit = []
omit-lockfile-registry-resolved = false
only = null
optional = null
os = null
otp = null
pack-destination = "."
package = []
package-lock = true
package-lock-only = false
parseable = false
prefer-dedupe = false
prefer-offline = false
prefer-online = false
prefix = "D:\\nodejs"
preid = ""
production = null
progress = true
provenance = false
provenance-file = null
; proxy = null ; overridden by user
read-only = false
rebuild-bundle = true
; registry = "https://registry.npmjs.org/" ; overridden by user
replace-registry-host = "npmjs"
save = true
save-bundle = false
save-dev = false
save-exact = false
save-optional = false
save-peer = false
save-prefix = "^"
save-prod = false
sbom-format = null
sbom-type = "library"
scope = ""
script-shell = null
searchexclude = ""
searchlimit = 20
searchopts = ""
searchstaleness = 900
shell = "C:\\Windows\\system32\\cmd.exe"
shrinkwrap = true
sign-git-commit = false
sign-git-tag = false
strict-peer-deps = false
; strict-ssl = true ; overridden by user
tag = "latest"
tag-version-prefix = "v"
timing = false
umask = 0
unicode = true
update-notifier = true
usage = false
user-agent = "npm/{npm-version} node/{node-version} {platform} {arch} workspaces/{workspaces} {ci}"
userconfig = "C:\\Users\\Administrator\\.npmrc"
version = false
versions = false
viewer = "browser"
which = null
workspace = []
workspaces = null
workspaces-update = true
yes = null

; "user" config from C:\Users\Administrator\.npmrc

https-proxy = null
proxy = null
registry = "https://registry.npmmirror.com"
strict-ssl = false

; "cli" config from command line options

long = true

Environment/Platform

Description

When i import the pipeline module,the above error accured import { pipeline } from "@xenova/transformers";

Reproduction

When i import the pipeline module,the above error accured import { pipeline } from "@xenova/transformers";

bekatan commented 1 month ago

I had the same issue. adding import { nodePolyfills } from "vite-plugin-node-polyfills"; export default defineConfig((configEnv) => ({ plugins: [ nodePolyfills({ exclude: ["stream"] }), ], })); to vite.config.ts seems to have resolved it. But now I get image My code is from the sentiment-analysis pipelines API docs image I have a vanilla typescript 5.4.3, with vite/5.2.2 win32-x64 node-v22.1.0 project

xenova commented 1 month ago

I think I should be able to just remote that import (since we don't support node < 18 anymore).

xenova commented 1 month ago

https://github.com/xenova/transformers.js/pull/752 should fix this.

customautosys commented 1 month ago

Hi I'm having a problem when importing @xenova/transformers in vite. Basically it's trying to import onnxruntime-node and sharp, which are not supposed to be imported as they are native modules, and this is causing all sorts of errors. I have also tried to ask here: https://github.com/vitejs/vite/pull/10314#issuecomment-2120673087

I've tried adding vite-plugin-node-polyfills and have removed it as it did not seem to help the errors.

@bekatan and @jzyzxx, do you know how to get @xenova/transformers working in a vite project?

xenova commented 1 month ago

@customautosys The default vite settings should be able to ignore these by looking at the package.json's browser field. Could you provide more information about your environment?

See here for an example: https://github.com/xenova/transformers.js/tree/main/examples/depth-anything-client

customautosys commented 1 month ago

@customautosys The default vite settings should be able to ignore these by looking at the package.json's browser field. Could you provide more information about your environment?

See here for an example: https://github.com/xenova/transformers.js/tree/main/examples/depth-anything-client

I am using https://github.com/quasarframework/quasar

I asked them and they said the cache for the node_modules is built by Vite and it's not something Quasar does.

I don't know why Vite seems to be ignoring the browser field. I've tried Vite versions 3, 4 and 5 and nothing works. I couldn't find anything in the Vite documentation about any flag controlling whether the browser field is ignored.

customautosys commented 1 month ago

Hi @xenova, sorry to have bothered you. I solved this problem by upgrading @quasar/app-vite to ^2.0.0-beta.12 and vite to ^5.2.10.

Thanks anyway!