Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[✅] fixes for all "Error: Missing Qwik City Env Data" #6237

Open
PatrickJS opened this issue May 6, 2024 · 56 comments
Open

[✅] fixes for all "Error: Missing Qwik City Env Data" #6237

PatrickJS opened this issue May 6, 2024 · 56 comments
Labels
COMP: qwik-city STATUS-2: team is working on this Scheduled for work by the core team TYPE: bug Something isn't working

Comments

@PatrickJS
Copy link
Member

PatrickJS commented May 6, 2024

(If you never seen this error then ignore this)

This is a live thread for different ways to fix Error: Missing Qwik City Env Data which can be caused by many different errors.

Error: Missing Qwik City Env Data
    at AsyncFunction.Aa (file:///Temp/server/q-DNo4f3Gn.js:15:11868)
    at AsyncFunction.dc (file:///Temp/server/q-DNo4f3Gn.js:10:5874)
    at AsyncFunction.V (file:///Temp/server/q-DNo4f3Gn.js:10:5808)
    at file:///Temp/server/q-DNo4f3Gn.js:15:2935
    at q (file:///Temp/server/q-DNo4f3Gn.js:7:1510)
    at file:///Temp/server/q-DNo4f3Gn.js:15:2804
    at file:///Temp/server/q-DNo4f3Gn.js:8:4693
    at Qt (file:///Temp/server/q-DNo4f3Gn.js:7:1430)
    at Et (file:///Temp/server/q-DNo4f3Gn.js:8:4686)
    at wi (file:///Temp/server/q-DNo4f3Gn.js:8:9122)

Your error might be one of the many fixes listed below

if any of these fixed your issue add a reaction to this post. Otherwise add a comment if you're still stuck

1. cookie issue

"I faced the same issue, but it was only due to the hostname/domain (localhost) having data of previous app stored in it. It solved itself when I cleared cookies and site data"

clear cookies and site data

2. accidentally importing server-only packages on the client

you might have accidentally imported a server-only package onto the client during development.

move server-only code into routeLoader$ or server$

3. deps in "dependencies" not in "devDependencies"

you might have dependencies in "dependencies" inside package.json that are being excluded. Move the packages into "devDependencies" unless they're server-only packages or packages with production binary e.g "bcrypt"

move app dependencies in package.json into "devDependencies"

4. when resizing window on local dev

sometimes when installing a new qwik app you may see this error when resizing the window. This is sometimes caused when the source-maps aren't loading

restart the dev server (comment here and ping me if this doesn't work)

5. partytown install

when installing qwik party town there can be an error with the QwikPartyTown component

remove <QwikPartytown forward={['dataLayer.push', 'fbq']} /> in root.tsx

@PatrickJS PatrickJS added COMP: docs Improvements or additions to documentation STATUS-1: needs triage New issue which needs to be triaged and removed COMP: docs Improvements or additions to documentation STATUS-1: needs triage New issue which needs to be triaged labels May 6, 2024
@PatrickJS PatrickJS changed the title [🫡] fixes for all "Error: Missing Qwik City Env Data" [✅] fixes for all "Error: Missing Qwik City Env Data" May 6, 2024
@PatrickJS PatrickJS pinned this issue May 6, 2024
@Nefcanto
Copy link

Nefcanto commented May 6, 2024

@PatrickJS, thank you for creating this thread. But I think it's not a good idea to expect developers to memorize the list you presented. The correct way is to give correct messages. Please let me repeat myself:

The right way is to give correct error messages

That's the first line for troubleshooting and debugging.

@PatrickJS
Copy link
Member Author

PatrickJS commented May 6, 2024

yes, this is only temporary until we track down each error and fix them. The error itself is triggered more often by other errors (which we need to correctly capture)

@PatrickJS PatrickJS unpinned this issue May 8, 2024
@seanperez-xyz
Copy link

happens all the time in firefox... if you open up devtools automatically does that

@seanperez-xyz
Copy link

seanperez-xyz commented May 24, 2024

there was alot of errors before in dev mode that dont pop up anymore... they still do in the console but before there was an error about some image thing that the dev tools injects some container ( it would mess up my css all the time) maybe whatever was done to mute that started throwing this errors ?

  • i like adding grid directly to the body... so i remember that error it was like a container that was like 0px x 0px would sit up in the top left and actually had a flag (tooltip-ish ordeal) that would always be there saying something about image needed width height... but even if you had no images ( pertained to the container itself) it would be there... but that thing would mess up my whole css, but I notice the console, still logs the error... but that little "flag "doesnt show up on the top left, but def when you open up dev tools in firefox the second you open it up it throws the qwik.env error ... something strange tho when in dev mode the vite and qwik trys to throw a bunch of stuff in which is ignored by firefox ( like all the -web kit stuff) .. just kind of seems like thats an "Env" thing + that new qwik.env.d.ts file I keep asking what its about but no one knows

@PatrickJS
Copy link
Member Author

What's the reproduction? Is it just new qwik app 1.5.5 and open dev mode in Firefox

@seanperez-xyz
Copy link

What's the reproduction? Is it just new qwik app 1.5.5 and open dev mode in Firefox

well i just got 1.5.5 and it does the same thing but 15.4 did it do

@PatrickJS
Copy link
Member Author

@JerryWu1234 do you have time to look into this bug?

@JerryWu1234
Copy link
Contributor

@JerryWu1234 do you have time to look into this bug?

Ok I can do

@JerryWu1234
Copy link
Contributor

image
everything is fine .
@seanperez-xyz Could you reproduce this bug ?

@gustavocadev
Copy link
Contributor

It happens to me when I use a context provider in the main layout

@redoPop
Copy link

redoPop commented Jun 26, 2024

I just saw another instance of this error triggered when using a hook that returned a single property from a context-bound Store:

export const useFoo = () => {
  const store = useContext(MyContext);
  return store.foo;
};

The issue was resolved by abandoning the hook and instead retrieving and destructuring the complete store within components:

const { foo } = useContext(MyContext);

@brunsten
Copy link

brunsten commented Jun 28, 2024

I just got it in a new app with

node -v
> v18.17.1 

npm create qwik@latest
npx qwik add fastify

And if i hit a 404 route, i.e posting via postman to a random endpoint - i dont get a 404 and instead i get this error.

@devcaeg
Copy link

devcaeg commented Jun 29, 2024

Qwik version 1.6 is causing this error to appear constantly in my application.

@wmertens
Copy link
Member

@devcaeg in dev mode or production? Could you make a repro?

@7ojo
Copy link

7ojo commented Jun 30, 2024

After upgrading to 1.6 seems I can not also get rid off this. Dev mode.

I have to re-run "npm start" on every change.

@devcaeg
Copy link

devcaeg commented Jun 30, 2024

It happens to me in development mode and it is constantly. For the moment I will go back to the previous version, since version 1.6 makes it impossible for me to work.

I will try to make a minimal reproduction of the error so that it can be investigated.

@wmertens
Copy link
Member

wmertens commented Jul 1, 2024

@gioboa I'm also experiencing it but when I revert the assetsDir commit, I don't experience this any more

@wmertens
Copy link
Member

wmertens commented Jul 1, 2024

@gioboa I take that back, it's still broken. Not sure why it worked for a bit.

@frankroc2022
Copy link

Went back from 1.6 to 1.5.7. If I have no route [...catchall] I get the same error "Missing Qwik City Env Data for help visit #6237" but If I have a [...catchall] route I get this error "TypeError: error loading dynamically imported module: http://localhost:5173/src/components/ts/global_component_4w7djkoecc8.js%3Ft%3D1719875176718". A fresh 1.6 install has not these problems.

@gioboa
Copy link
Member

gioboa commented Jul 1, 2024

Went back from 1.6 to 1.5.7. If I have no route [...catchall] I get the same error "Missing Qwik City Env Data .....

Can you share with us your repo with the bere minimum stuffs? I would like to face this error because it is so annoying

@wmertens
Copy link
Member

wmertens commented Jul 3, 2024

I'm encountering it when hot reloading. First render, everything is fine, but change some code, and Vite re-runs entry.ssr without providing a request and then the qwik city server data is missing.

Probably the fix is to have module.hot.accept in the right places

@sprappcom
Copy link

sprappcom commented Jul 3, 2024

@wmertens is there a quick fix i can do now? what do u mean module.hot.accept in the right places?

i'm having this issue persistently. i need to CTRL+C my npm start and restart it again instead of having hot reload

@devcaeg
Copy link

devcaeg commented Jul 3, 2024

@sprappcom

In the meantime use version 1.5.7 instead of 1.6.

@boris-schwarz
Copy link

I just had the same creating my first Qwik App (1.6). I tried it twice, once with the proposed Default Starter and once with the Empty Starter.

The default starter opened, but there was no interactivity, neither on the very first button, nor on the counter below. However the Alt+Click seemed to work.

I tried again with the empty starter and adding a dummy counter by myself, for some interaction.

In both cases I got a js error in the console in the following format:

Uncaught (in promise) TypeError: URL constructor: //%40fs/C%3A%5Cprojects%5Cqwik-city-app%5Csrc%5Ccomponents%5Ccounter/counter_component_button_onclick_sefr0m6h0sk.js?_qrl_parent=C%3A%5Cprojects%5Cqwik-city-app%5Csrc%5Ccomponents%5Ccounter%5Ccounter.tsx#Counter_component_button_onClick_seFR0M6H0sk[0] is not a valid URL.
    dispatch http://localhost:5173/:126
    processDocumentEvent http://localhost:5173/:201
    addEventListener http://localhost:5173/:233
    processEventOrNode http://localhost:5173/:241
    processEventOrNode http://localhost:5173/:241
    <anonymous> http://localhost:5173/:264

Not sure if it's correct to trying to access my file system instead of http://localhost. I was using Firefox Developer Edition, also tried in Google Chrome with no success.

I tried then to use Qwik 1.5.7 instead of 1.6, and the env error didn't appear again, howevery the error above (URL constructor) still appears in the console and there's no interactivity.

Using Windows 11, Node v20.14.0, Npm 10.4.0, killing the process and running npm start unfortunately didn't do the trick.

Maybe those are related, thought I'd let you know.

@wmertens
Copy link
Member

wmertens commented Jul 4, 2024

I think I may have a fix for the situation I explained above, here #6629 (comment)

It makes sure that the vite dev server recognizes qrl segment requests better and doesn't try to SSR them.

@boris-schwarz please try with the npm packages I linked

@Nefcanto
Copy link

Nefcanto commented Jul 7, 2024

@wmertens, @gioboa, @PatrickJS , is there a way to show the stack related to the code of us in error?

As I stated above in this thread, the main problem is the lack of information. We don't know why how and where. We have to get into heuristics (trial and error) and restart the app, reboot the system, delete, re-clone, and whatnot.

If you can give us more info on the stack, that would help solve lots of problems.

@Nefcanto
Copy link

Nefcanto commented Jul 7, 2024

@wmertens, @gioboa, @PatrickJS, based on the stack:

12:52:28 PM [vite] Internal server error: Missing Qwik City Env Data for help visit https://github.com/QwikDev/qwik/issues/6237
  File: /npm/dist-dev/tsc-out/packages/qwik/src/core/util/implicit_dollar.js:3665:22
      at AsyncFunction.QwikCityProvider_component_TxCFOy819ag [as resolved] (/npm/node_modules/@builder.io/qwik-city/index.qwik.mjs:659:11)
      at AsyncFunction.invokeApply (/npm/dist-dev/tsc-out/packages/qwik/src/core/util/implicit_dollar.js:3665:22)
      at AsyncFunction.invoke (/npm/dist-dev/tsc-out/packages/qwik/src/core/util/implicit_dollar.js:3658:22)
      at /npm/dist-dev/tsc-out/packages/qwik/src/core/util/implicit_dollar.js:7297:21
      at maybeThen (/npm/dist-dev/tsc-out/packages/qwik/src/core/util/implicit_dollar.js:384:54)
      at /npm/dist-dev/tsc-out/packages/qwik/src/core/util/implicit_dollar.js:7289:25
      at /npm/dist-dev/tsc-out/packages/qwik/src/core/util/implicit_dollar.js:1043:25
      at safeCall (/npm/dist-dev/tsc-out/packages/qwik/src/core/util/implicit_dollar.js:373:21)
      at executeComponent (/npm/dist-dev/tsc-out/packages/qwik/src/core/util/implicit_dollar.js:1043:10)
      at renderSSRComponent (/npm/dist-dev/tsc-out/packages/qwik/src/core/util/implicit_dollar.js:1405:20)

I see that the method executeComponent is called. Based on that I assume that we have the knowledge of where we are. If you can append that knowledge to the end of this line, it would be very helpful:

throw new Error(Missing Qwik City Env Data for help visit https://github.com/QwikDev/qwik/issues/6237);

@Nefcanto
Copy link

Nefcanto commented Jul 7, 2024

And when I get that error, I get this error to in my console:

Loading module from “https://project.local/src/Components/Layout/fixeditems_component_k4eriarhpky.js%3Ft%3D1720357551969” was blocked because of a disallowed MIME type (“text/html”).

And in that file, I have this code:



    useOnWindow(
        "scroll",
        $(() => {
            if (window.scrollY > 400) {
                isShownUp.value = true
            } else {
                isShownUp.value = false
            }
        })
    )

When I delete this code snippet, then the error goes away.

@7ojo
Copy link

7ojo commented Jul 8, 2024

Also when looking at network panel I noticed this error "NS_ERROR_CORRUPTED_CONTENT" for this request

GET http://localhost:5173/node_modules/%40builder.io/qwik-city/link_component_handleprefetch_osdg8fnytw4.js%3Ft%3D1720423501167

@wmertens
Copy link
Member

wmertens commented Jul 8, 2024

@7ojo that's 1.6.0, we already know that's broken. Please test #6629 (comment)

@PatrickJS
Copy link
Member Author

@wmertens do you think this pr caused the problems in 1.6.0 96ae4c6

@wmertens
Copy link
Member

wmertens commented Jul 9, 2024

FYI the 1.6.0 errors are fixed in 1.7.0. This doesn't fix all cases because the message applies to many different errors.

@boris-schwarz
Copy link

Hey, sorry for the late reply. My case has indeed been fixed with 1.7.0, thanks a lot.

@devcaeg
Copy link

devcaeg commented Jul 10, 2024

Now version 1.7 has another error that forces to roll back to version 1.5.7.

Error: TypeError: Failed to fetch dynamically imported module:

@devcaeg
Copy link

devcaeg commented Jul 10, 2024

Now version 1.7 has another error that forces to roll back to version 1.5.7.

Error: TypeError: Failed to fetch dynamically imported module:

This bug exists since version 1.6, but the other bug in version 1.6 used to appear before this bug. But now in version 1.7, this error appears constantly.

@frankroc2022
Copy link

frankroc2022 commented Jul 11, 2024

I responded here #6629.

@upayanmazumder
Copy link

Facing the same issue. Check the last commit on this branch https://github.com/upayanmazumder/Pterodactyl-Management-Dashboard/tree/Missing-env-data-issue

@upayanmazumder
Copy link

Facing the same issue. Check the last commit on this branch https://github.com/upayanmazumder/Pterodactyl-Management-Dashboard/tree/Missing-env-data-issue

btw the deployment on cf for this branch wont work as it isnt configured to work that way. try to run it locally. my api server is at pmdapi.upayan.space

@frankroc2022
Copy link

1.7.1 solved all my problems, thx!

@wmertens
Copy link
Member

@upayanmazumder please minimally reproduce the error with 1.7.1

@Kampouse
Copy link
Contributor

@wmertens
been trying to add stuff into the docs and getting this error frequently within usvisible,usedocument
#6689

@yasserlens
Copy link

yasserlens commented Jul 17, 2024

One more reason this "Error: Missing Qwik City Env Data" appears (took me hours to figure out..):
When an endpoint (onGet, onPost, etc) is defined but isn't returning a response, valid or not.
Here's a minimal reproduction with v1.5.7:
https://stackblitz.com/edit/qwik-starter-3g4hsc?file=src%2Froutes%2Fapi%2Femail-list%2Findex.tsx

The same happens on v1.7.1 - reproduced below:
https://stackblitz.com/edit/qwik-starter-9zkk3z?file=src%2Froutes%2Fapi%2Femail-list%2Findex.tsx

To fix the error - uncomment the "text(200, 'hello');" line in the onGet endpoint inside routes/api/email-list/index.tsx.

I had no idea what the reason was - until i read somewhere that having an invalid image URL would cause this.

@shairez
Copy link
Contributor

shairez commented Jul 23, 2024

@wmertens can you please add the relevant fix context you have?

Thanks

@maiieul maiieul removed the P4: urgent If Bug - it makes Qwik unstable and affects the majority of users label Aug 17, 2024
@maiieul
Copy link
Contributor

maiieul commented Aug 24, 2024

This seems to be related to requesting a bad request in some sort or another.

For example using

      <script
        type="speculationrules"
        dangerouslySetInnerHTML={`{"prefetch":[{"urls":["/about/index.html"]}]}`}
      />

will lead to this error.

while

      <script
       type="speculationrules"
       dangerouslySetInnerHTML={`{"prefetch":[{"urls":["/about/"]}]}`}
     /> 

won't.

MRE: https://github.com/maiieul/qwik-missing-env-data-repro

@wmertens
Copy link
Member

The most common reason is that SSR is called on a URL that shouldn't be SSR'd.

The SSR handler in qwik city should check the context before rendering

@JakeAsunto
Copy link

JakeAsunto commented Aug 25, 2024

the error seems to appear when you delete the main index.tsx in the "routes" folder

@wmertens
Copy link
Member

wmertens commented Aug 26, 2024

I added a commit to this draft PR that may expose the problem earlier in dev:

7e2ce01

@Rleslie321
Copy link

I am able to get this bug by opening multiple tabs in chrome and then opening devtools.

MRE:

npm create qwik@latest
npm run dev

duplicate the localhost tab three times and then open the devtools on the third tab

@CharlesStover
Copy link
Contributor

CharlesStover commented Oct 2, 2024

This happens only when I specify a --host when running vite for dev mode. None of the provided solutions above resolve it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
COMP: qwik-city STATUS-2: team is working on this Scheduled for work by the core team TYPE: bug Something isn't working
Projects
Status: Upcoming
Development

No branches or pull requests