Static JS file "was not found" on intial page request (but ok after subsequent requests)
See original GitHub issueDescribe the bug
I am getting some unexpected behavior involving use of an external (non svelte) that is intended to be invoked after svelte-kit renders the initial page.
In my src/routes/index.svelte
file I have the following:
<svelte:head>
<script src="/js/index.bundle.js"></script>
</svelte:head>
// and then in this same .svelte file also a <script> , some html content and a <style> section )
The JS file I have bundled separately (outside of svelte land) and just needs to run after my initial svelte powered index runs; I’m not sure if there is a better way to wait for svelte to finish rendering but currently I just am using a 500ms delay in this particular external script.
Anyway, that is beside the point - the main problem is this error on the first request I make (see log)
(but actually I just tested the production build ie- yarn build
and noticed there were no such problems; so evidently this only occurs in dev mode. And another reason this isn’t such a big deal is even in dev mode the bundle ‘was not found’ msges go away on subsequent requests; ie- i just have to reload the page once and my external bundle works as intended… so just thought I would share this; not sure why that initial request is not working as intended I supppose the only inconvenience is that I have to remind other collaborators on my project to refresh the index page once it loads initially after starting in dev mode)
Reproduction
😕
Logs
drs@mypc:/dev/project$ yarn dev
yarn run v1.22.10
warning package.json: No license field
$ svelte-kit dev --port 3027
SvelteKit v1.0.0-next.115
local: http://localhost:3027
network: not exposed
network: not exposed
network: not exposed
Use --host to expose server to other devices on this network
## (idles here until requesting my index page ie- localhost:3027/ aka ./src/routes/index.svelte )
warn - You have enabled the JIT engine which is currently in preview.
warn - Preview features are not covered by semver, may introduce breaking changes, and can change at any time.
[svelte-preprocess] The file "/js/index.bundle.js" was not found.
[vite-plugin-svelte] /dev/project/src/routes/index.svelte:96:1 Unused CSS selector "p"
[svelte-preprocess] The file "/js/index.bundle.js" was not found.
System Info
System:
OS: Linux 5.11 Ubuntu 20.04.2 LTS (Focal Fossa)
CPU: (24) x64 AMD Ryzen 9 3900X 12-Core Processor
Memory: 831.66 MB / 15.58 GB
Container: Yes
Shell: 5.0.17 - /bin/bash
Binaries:
Node: 14.17.4 - ~/n/bin/node
Yarn: 1.22.10 - ~/n/bin/yarn
npm: 6.14.14 - ~/n/bin/npm
Browsers:
Firefox: 90.0.2
npmPackages:
@sveltejs/adapter-node: ^1.0.0-next.26 => 1.0.0-next.26
@sveltejs/adapter-static: ^1.0.0-next.13 => 1.0.0-next.13
@sveltejs/kit: next => 1.0.0-next.115
svelte: ^3.34.0 => 3.38.2
Severity
annoyance
Additional Information
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (4 by maintainers)
Can’t reproduce this, and the original comment put ‘😕’ in place of a repro so I’ll close this.
Note that script tags in a
<svelte:head>
won’t load and execute synchronously when client-side navigating to a page, so any globals it creates etc can’t be accessed immediatelyIIRC the compiler sends every script tag that it finds to the preprocessor, which in turn leads to
svelte-preprocess
trying to understand that “src” as if it were a component script tag. We need some mechanism to detect if it’s a root script tag or a nested one. I’m also not sure if that’s something that should be done in the preprocessor level.