vite-plugin-rsw
vite-plugin-rsw copied to clipboard
Doesn't handle SvelteKit w/ changed base path
Describe the bug When setting up the project as described in the Readme (onto a SvelteKit app), the application will not execute if the svelte config specifies an alternate base path:
svelte.config.js:
import adapter from '@sveltejs/adapter-auto';
/** @type {import('@sveltejs/kit').Config} */
const config = {
kit: {
adapter: adapter(),
paths: {
base: '/subfolder'
}
}
};
export default config;
To Reproduce Steps to reproduce the behavior:
- Create new SvelteKit project via 'npm create svelte@latest
' - Modify svelte.config.js as shown above (just set a base path).
- Follow steps as descibed in Readme to setup vite-plugin-rsw and create the default crate
- Start dev server with 'npm run dev'
Expected behavior The dev server should correctly resolve the WASM module to its actual location; not adjusted by base path.
Screenshots Not a screen shot, but here's the error I'm getting:
[1] Failed to load url /rsw-hello/pkg/rsw_hello.js (resolved id: D:/Git/demo-wasm/rsw-hello/pkg/rsw_hello.js). Does the file exist?
[1] Failed to load url /rsw-hello/pkg/rsw_hello.js (resolved id: D:/Git/demo-wasm/rsw-hello/pkg/rsw_hello.js). Does the file exist?
[1] Error: Not found: /subfolder/rsw-hello/pkg/rsw_hello.js
[1] at resolve (/node_modules/@sveltejs/kit/src/runtime/server/respond.js:395:13)
[1] at resolve (/node_modules/@sveltejs/kit/src/runtime/server/respond.js:236:5)
[1] at #options.hooks.handle (/@fs/D:/Git/demo-wasm/node_modules/@sveltejs/kit/src/runtime/server/index.js:41:55)
[1] at Module.respond (/node_modules/@sveltejs/kit/src/runtime/server/respond.js:233:40)
[1] at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Note that the two URLs at the top (D:/Git/demo-wasm/rsw-hello/pkg/rsw_hello.js) are actually correct, and I've confirmed that the files actually are there.
Desktop (please complete the following information):
- Windows 10
- Firefox
- vite-plugin-rsw: 2.0.11, vite: 4.04, @sveltejs/kit: 1.3.1
Please configure [[crates]] -> root and try again. https://github.com/rwasm/rsw-rs#options
Process won't even start:
[0] [🦀 rsw::crate] rsw-hello The system cannot find the path specified. (os error 3)
[0] rsw watch exited with code 1
Even attempted moving the crate into a folder called 'subfolder' afterwards:
[1] Failed to load url /subfolder/rsw-hello/pkg/rsw_hello.js (resolved id: D:/Git/demo-wasm/subfolder/rsw-hello/pkg/rsw_hello.js). Does the file exist?
[1] Error: Not found: /subfolder/subfolder/rsw-hello/pkg/rsw_hello.js
[1] at resolve (/node_modules/@sveltejs/kit/src/runtime/server/respond.js:395:13)
[1] at resolve (/node_modules/@sveltejs/kit/src/runtime/server/respond.js:236:5)
[1] at #options.hooks.handle (/@fs/D:/Git/demo-wasm/node_modules/@sveltejs/kit/src/runtime/server/index.js:41:55)
[1] at Module.respond (/node_modules/@sveltejs/kit/src/runtime/server/respond.js:233:40)
[1] at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
- How is your rsw.toml set up?
- Have you ever executed the
rsw watchcommand?
As I said in the OP, the rsw.toml file is exactly as it was described following the instructions in the Readme. However, here is a dump:
name = "rsw"
version = "0.1.0"
#! time interval for file changes to trigger wasm-pack build, default `50` milliseconds
interval = 50
#! link
#! npm link @see https://docs.npmjs.com/cli/v8/commands/npm-link
#! yarn link @see https://classic.yarnpkg.com/en/docs/cli/link
#! pnpm link @see https://pnpm.io/cli/link
#! The link command will only be executed if `[[crates]] link = true`
#! cli: `npm` | `yarn` | `pnpm`, default is `npm`
cli = "npm"
#! ---------------------------
#! rsw new <name>
[new]
#! @see https://rustwasm.github.io/docs/wasm-pack/commands/new.html
#! using: `wasm-pack` | `rsw` | `user`, default is `wasm-pack`
#! 1. wasm-pack: `rsw new <name> --template <template> --mode <normal|noinstall|force>`
#! 2. rsw: `rsw new <name>`, built-in templates
#! 3. user: `rsw new <name>`, if `dir` is not configured, use `wasm-pack new <name>` to initialize the project
using = "wasm-pack"
#! this field needs to be configured when `using = "user"`
#! `using = "wasm-pack"` or `using = "rsw"`, this field will be ignored
#! copy all files in this directory
dir = "my-template"
[[crates]]
name = "rsw-hello"
link = true
#! ################# NPM Package #################
#! When there is only `name`, other fields will use the default configuration
#! 📦 -------- package: rsw-hello --------
# [[crates]]
# #! npm package name (path: $ROOT/rsw-hello)
# name = "rsw-hello"
# #! run `npm link`: `true` | `false`, default is `false`
# link = false
#! 📦 -------- package: @rsw/utils --------
# [[crates]]
# #! npm package name (path: $ROOT/utils)
# name = "utils"
# # #! scope: npm org
# scope = "rsw"
# #! run `npm link`: `true` | `false`, default is `false`
# link = false
#! 📦 -------- package: @rsw/hello --------
# [[crates]]
# #! npm package name (path: $ROOT/@rsw/hello)
# name = "@rsw/hello"
# #! default is `.`
# root = "."
# #! default is `pkg`
# out-dir = "pkg"
# #! target: bundler | nodejs | web | no-modules, default is `web`
# target = "web"
# #! run `npm link`: `true` | `false`, default is `false`
# link = false
# #! rsw watch
# [crates.watch]
# #! default is `true`
# run = true
# #! profile: `dev` | `profiling`, default is `dev`
# profile = "dev"
# #! rsw build
# [crates.build]
# #! default is `true`
# run = true
# #! profile: `release` | `profiling`, default is `release`
# profile = "release"
As for the 'rsw watch' command, it was added to the 'dev' script as described be the Readme, so it runs everytime the dev server is started. It is also the source of the error messages I've been pasting.
Is the rsw-hello directory initialized under the project root path?
wasm-pack new rsw-hello
# or
rsw new rsw-hello
You can execute the rsw watch command separately and see if the rsw-hello/pkg/rsw_hello.js file is generated.
If there is an exception, please attach terminal all run information.
Is the
rsw-hellodirectory initialized under the project root path?
Yes
You can execute the
rsw watchcommand separately and see if thersw-hello/pkg/rsw_hello.jsfile is generated.
As I said before, the file is begin generated, it's just not being found. However, I did run these commands as you indicated and got the same output as before:
Failed to load url /rsw-hello/pkg/rsw_hello.js (resolved id: D:/Git/demo-wasm/rsw-hello/pkg/rsw_hello.js). Does the file exist?
Error: Not found: /subfolder/rsw-hello/pkg/rsw_hello.js
at resolve (/node_modules/@sveltejs/kit/src/runtime/server/respond.js:395:13)
at resolve (/node_modules/@sveltejs/kit/src/runtime/server/respond.js:236:5)
at #options.hooks.handle (/@fs/D:/Git/demo-wasm/node_modules/@sveltejs/kit/src/runtime/server/index.js:41:55)
at Module.respond (/node_modules/@sveltejs/kit/src/runtime/server/respond.js:233:40)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Your description doesn't help me locate the problem. Please submit the code to the github repository, including the files in rsw-hello.
Public repo: https://github.com/SenojLuap/demo-wasm
Failed to load url /rsw-hello/pkg/rsw_hello.js (resolved id: /Users/lencx/github/demo-wasm/rsw-hello/pkg/rsw_hello.js). Does the file exist?
Error: Not found: /rsw-hello/pkg/rsw_hello.js
at resolve (/node_modules/@sveltejs/kit/src/runtime/server/respond.js:395:13)
at resolve (/node_modules/@sveltejs/kit/src/runtime/server/respond.js:236:5)
at #options.hooks.handle (/node_modules/@sveltejs/kit/src/runtime/server/index.js:41:55)
at Module.respond (/node_modules/@sveltejs/kit/src/runtime/server/respond.js:233:40)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
The request url "/Users/lencx/github/demo-wasm/rsw-hello/pkg/rsw_hello.js" is outside of Vite serving allow list.
- /Users/lencx/github/demo-wasm/src/lib
- /Users/lencx/github/demo-wasm/src/routes
- /Users/lencx/github/demo-wasm/.svelte-kit
- /Users/lencx/github/demo-wasm/src
- /Users/lencx/github/demo-wasm/node_modules
Refer to docs https://vitejs.dev/config/server-options.html#server-fs-allow for configurations and more details.
svelte config changed, restarting vite dev-server. changed file: /Users/lencx/github/demo-wasm/svelte.config.js
The resource you are accessing is not allowed, you can check the documentation and just do the configuration below. https://vitejs.dev/config/server-options.html#server-fs-allow
import { sveltekit } from '@sveltejs/kit/vite';
import { ViteRsw } from 'vite-plugin-rsw';
const config = {
plugins: [sveltekit(), ViteRsw()],
server: {
fs: {
// Allow serving files from one level up to the project root
allow: ['..'],
},
}
};
export default config;
How did you get that additional output? That would have made the problem much easier to understand