tauri-apps / vue-cli-plugin-tauri

Turn your Vue SPA into a lightweight cross-platform desktop app
https://tauri.studio
MIT License
372 stars 23 forks source link

tauri fs APIs not working #10

Closed Sparkenstein closed 4 years ago

Sparkenstein commented 4 years ago

i am using this vue plugin for testing tauri out. Not sure if the issue is with tauri core of this plugin.

I have a simple js file that has following

import { readDir } from "tauri/api/fs";

readDir(".").then(d => {
    console.log(d)
})

export default 1;

the default export is just so that I can import this file in my App.vue and nothing else. intellisense shows that this code is correct and I can navigate through it as well, but after running it with yarn tauri:serve I get following error

CONSOLE LOG [HMR] Waiting for update signal from WDS...
undefined:73:56: CONSOLE ERROR TypeError: undefined is not an object (evaluating '_tauri__WEBPACK_IMPORTED_MODULE_0__["default"].readDir')
CONSOLE INFO Download the Vue Devtools extension for a better development experience:

This is the entire error unfortunately, there's no stack trace or anything.

nklayman commented 4 years ago

It works fine for me on Manjaro linux. Try with a vue cli project and see if it works there. Tauri was also updated recently, so make sure you are using the latest version by deleting your yarn.lock/package-lock.json and reinstalling deps.

Sparkenstein commented 4 years ago

It's a weird Issue. I tried your suggestion first, deleted node_modules and yarn.lock, reinstalled deps and still same error above. Then I created entire new app, with standard commands as it's just simple testing code. still same issue. Steps I followed are below:

If I run this I get same Error I mentioned above.

2

but weird thing is if I change the code to

console.log(readDir)

I can see the function definition properly.

3

My cargo.toml has tauri = { version = "0.5", features = [ "all-api", "edge" ] } added by vue tauri plugin. yarn tauri info shows follwing information:

yarn run v1.22.4
$ /home/spark/newapp/node_modules/.bin/tauri info
[tauri]: running info

Operating System - Linux(5.3.0-51-generic) - linux/x64

Node.js environment
  Node.js - 12.16.2
  tauri.js - 0.6.2

Rust environment
  rustc - 1.43.0
  cargo - 1.43.0
  tauri-bundler - 0.6.0

Global packages
  NPM - 6.14.4
  yarn - 1.22.4

App directory structure
/.git
/node_modules
/public
/src
/src-tauri

App
  tauri - 0.5
  mode - embedded-server
  build-type - bundle
  CSP - default-src blob: data: filesystem: ws: http: https: 'unsafe-eval' 'unsafe-inline'
  Windows - Edge
  distDir - unset
  devPath - unset
Done in 0.67s.

Let me know if you need any more logs or config from my side.

fedot commented 4 years ago

In a similar manner none of the APIs are working for me on windows while running with devmode/HMR with npm run tauri:serve Yet the the binaries produced by result of npm run tauri:build work as expected.

Update:, if I'm developing by running both npm run serve and npx tauri dev (and not npm run tauri:serve) everthing works as expected too.

Sparkenstein commented 4 years ago

@fedot Good catch. Can confirm this behaviour. keeping two terminals open for yarn serve and yarn tauri dev worked for me. Although running yarn tauri:build didn't as the AppImage file created by kept giving me exec format error. But that's a different issue.

nklayman commented 4 years ago

Alright, seems like this is a windows-only issue then since I just tried on a fresh linux install and it worked fine. I don't have a working windows install right now, so it may be a few days before I can set that up and then take a look at this.

nklayman commented 4 years ago

Just realizing now that you are on linux, idk why I thought windows. But I also tried on windows and it worked fine. I'm not sure why you are getting the issue, but another tauri release has been published so maybe try that.

nothingismagick commented 4 years ago

We're seeing some cases where you have to manually remove src-tauri/target.

fedot commented 4 years ago

I can confirm it works with the new version