I'm just playing with a basic js app with npm, and the tauri api docs show the import syntax as, e.g. import { writeTextFile, BaseDirectory } from '@tauri-apps/api/fs'; I'm out of ideas - this is the inspect console error: TypeError: Module specifier, '@tauri-apps/api/fs' does not start with "/", "./", or "../". Prefixing with "/" or "./" does not help. Using "/@tauri-apps ..." gives a new error: TypeError: 'text/html' is not a valid JavaScript MIME type (same for "./@tauri-apps"). I'm discouraged. What the heck is going on?
#day 1 noob problem - I can't seem to import anything at all from "@tauri-apps/api/"
8 messages · Page 1 of 1 (latest)
are you using a Javascript bundler or frontend tool like Vite or Webpack?
Because that import only works within a bundler environment (the bundler then takes your JS files and turns them into optimized JS files the browser actually understands)
The docs can be misleading, sometimes you'll find better answers in git issues.
If you are using vanillajs then you need to enable withGlobalTauri and use window.__TAURI__.fs as such:
const { writeTextFile, BaseDirectory } = window.__TAURI__.fs;
instead of:
import { writeTextFile, BaseDirectory } from '@tauri-apps/api/fs';
There's a lot of assumptions in this framework 🤔
Based on your insight, I created a NextJs app, and the imports work as described. Thank you for that!
I see, thank you! I feel like I was circling all around this. Now I am finally getting some traction with vanillajs :)