perry-mitchell / webdav-client

WebDAV client written in Typescript for NodeJS and the browser
MIT License
661 stars 143 forks source link

Error module stream with client.putFileContents in vite app #330

Closed mv-debug closed 1 year ago

mv-debug commented 1 year ago

Hi all,

I use this module and it connects with my webdav server (Nextcloud 24) but if I put a file to the server via

const resp = await client.putFileContents("file.txt", "just a test", { overwrite: false });

I got this error:

_browser-external:stream:3 Uncaught (in promise) Error: Module "stream" has been externalized for browser compatibility and cannot be accessed in client code. at Object.get (browser-external:stream:3:11) at putFileContents.js:65:118 at step (putFileContents.js:33:23) at Object.next (putFileContents.js:14:53) at putFileContents.js:8:71 at new Promise () at awaiter (putFileContents.js:4:12) at putFileContents (putFileContents.js:54:12) at Object.putFileContents (factory.js:76:92) at Proxy.save_to_nc (App.vue:86:33) get @ browser-external:stream:3 (anonymous) @ putFileContents.js:65 step @ putFileContents.js:33 (anonymous) @ putFileContents.js:14 (anonymous) @ putFileContents.js:8 awaiter @ putFileContents.js:4 putFileContents @ putFileContents.js:54 putFileContents @ factory.js:76 save_tonc @ App.vue:86 Promise.catch (async) callWithAsyncErrorHandling @ runtime-core.esm-bundler.js:168 invoker @ runtime-dom.esm-bundler.js:345

Here is my package.json

{
  "name": "node-starter",
  "version": "0.0.0",
  "scripts": {
    "dev": "vite --port 5173",
    "build": "vite build",
    "serve": "vite preview"
  },
  "devDependencies": {
    "autoprefixer": "^10.4.2",
    "daisyui": "^2.6.0",
    "postcss": "^8.4.7",
    "tailwindcss": "^3.0.23",
    "vite": "^2.8.6"
  },
  "dependencies": {
    "@vitejs/plugin-vue": "^2.3.3",
    "vue": "^3.2.45",
    "webdav": "^4.11.2"
  }
}

Thank you in advance.

It will be great if anybody could help me.

Best

Michael

mv-debug commented 1 year ago

I have to use:

import { createClient } from "webdav/web";

To avoid using node-fetch. :)

perry-mitchell commented 1 year ago

Glad you found the solution. This could be better improved using the exports definition in ESM.. something to consider for the next stable version.