#Tauri + Vanilla JS + import?

12 messages · Page 1 of 1 (latest)

hasty sluice
#

I am getting TypeError: Module name, '@tauri-apps/api/shell' does not resolve to a valid URL. when attempting to execute import { Command } from '@tauri-apps/api/shell' in JS.

But it works fine with const { Command } = window.__TAURI__.shell;.

languid stone
#

That's because you need a bundler of some kind to use that syntax

#

Like Vite, Webpack or Rollup

hasty sluice
#

Oh thank u Simon. My simple cause was just trying to include a .js file inside another .js file. Without adding any bundler additionally, the simplest way for me is to include both .js files in <script> tag in html?

languid stone
#

Both yes and no. As your project grows that'll start to create really, really poorly performing pages since you add so many scripts to load. It'd be better then to load scripts dynamically by adding script tags when the relevant code is needed

I strongly urge you to start looking at using a framework instead of using vanilla js, because in a couple months you'll discover that what you've been doing is developing your own mini framework

hasty sluice
#

That is correct, been in this situation before. Thanks, will switch to a framework.

#

One last thing. Webpack seems quite fine and minimal, is this what I need to add? npm install @tauri-apps/tauri-webpack?

languid stone
#

There's a tauri-webpack package?

#

Ah, it's 4 years old

#

Almost as old as the project itself lol

hasty sluice
#

hehe

languid stone
#

I would urge you to use Vite instead because Webpack is the larger of them