question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Static JS file "was not found" on intial page request (but ok after subsequent requests)

See original GitHub issue

Describe 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:closed
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Rich-Harriscommented, Apr 26, 2022

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 immediately

0reactions
kaisermanncommented, Aug 9, 2021

(maybe it’s using a regex to find <script> tags and doesn’t ignore them when inside svelte:head)

IIRC 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Express-js can't GET my static files, why? - Stack Overflow
This solved my issue. In my code, path to CSS was working fine even with the __dirname concatenation (using path.join), while fetching js...
Read more >
Fixing Common Problems with CORS and JavaScript
Tutorial: This post walks through troubleshooting and fixing common problems associated with calling REST APIs from JavaScript.
Read more >
Handling common JavaScript problems - MDN Web Docs
After the packages have finished installing, try loading up a JavaScript file: you'll see any issues highlighted with green (for warnings) and ...
Read more >
Server Side Rendering (SSR) vs. Client Side Rendering (CSR ...
In this case when a browser requests a webpage, the initial server request returns a minimal HTML file that serves as the application...
Read more >
Serving static files — Let's Go (Sample)
When this handler receives a request, it will remove the leading slash from the URL path and then search the ./ui/static directory for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found