Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 of 5 tasks
jzyzxx opened this issue May 8, 2024 · 7 comments · Fixed by #752
Closed
1 of 5 tasks

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

jzyzxx opened this issue May 8, 2024 · 7 comments · Fixed by #752
Labels
bug Something isn't working

Comments

@jzyzxx
Copy link

jzyzxx commented May 8, 2024

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

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

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";

@jzyzxx jzyzxx added the bug Something isn't working label May 8, 2024
@bekatan
Copy link

bekatan commented May 10, 2024

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
Copy link
Owner

xenova commented May 10, 2024

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

@xenova
Copy link
Owner

xenova commented May 10, 2024

#752 should fix this.

@customautosys
Copy link

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: vitejs/vite#10314 (comment)

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
Copy link
Owner

xenova commented May 20, 2024

@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
Copy link

@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
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants