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

Cannot access 'tc' before initialization #363

Closed
aligzl opened this issue Nov 2, 2024 · 19 comments
Closed

Cannot access 'tc' before initialization #363

aligzl opened this issue Nov 2, 2024 · 19 comments
Labels
question Further information is requested

Comments

@aligzl
Copy link

aligzl commented Nov 2, 2024

Describe the bug
Hi, i cant deploy my app as getting error about hubDatabase during the deployment

17:48:42.892 Error: Failed to publish your Function. Got error: Uncaught ReferenceError: Cannot access 'tc' before initialization
at chunks/nitro/nitro.mjs:1:588600 in useRuntimeConfig
at chunks/nitro/nitro.mjs:1:225944 in requireNuxtHubFeature
at chunks/nitro/nitro.mjs:1:444655 in hubDatabase
at chunks/nitro/nitro.mjs:1:458639

Steps to reproduce
Steps to reproduce the behavior:
Deplyment Logs

@atinux
Copy link
Contributor

atinux commented Nov 2, 2024

What is displayed when your run npx nuxi info?

@aligzl
Copy link
Author

aligzl commented Nov 2, 2024

What is displayed when your run npx nuxi info?

@aligzl
Copy link
Author

aligzl commented Nov 2, 2024

i am also getting this error even i didnt update any deps during dev

[worker reload] [worker init] .nuxt/dev/index.mjs failed

i assume that this error comes from nuxt related to #6712 and #2832

@aligzl
Copy link
Author

aligzl commented Nov 2, 2024

instaling "nitropack": "2.9.7" and adding

"overrides": {
  "nitropack": "2.9.7"
}

to package.json solved my issue for now

@pi0
Copy link

pi0 commented Nov 2, 2024

✅ Nitro 2.10.1 is released with a (related) fix. Recreating lock file should solve the problem.

@aligzl aligzl closed this as completed Nov 3, 2024
@aligzl
Copy link
Author

aligzl commented Nov 3, 2024

Hi Getting this error during deployment

Error: Failed to publish your Function. Got error: Uncaught Error: Missing Cloudflare DB binding (D1)
at chunks/nitro/nitro.mjs:1:68337 in createError$1
at chunks/nitro/nitro.mjs:1:489144 in hubDatabase
at chunks/nitro/nitro.mjs:1:500109

@aligzl aligzl reopened this Nov 3, 2024
Copy link
Contributor

atinux commented Nov 4, 2024

Could you please try with nuxthub/core 0.8.5?

@aligzl
Copy link
Author

aligzl commented Nov 4, 2024

Could you please try with nuxthub/core 0.8.5?

Still same error with fallowing

Error: Failed to publish your Function. Got error: Uncaught Error: Missing Cloudflare DB binding (D1)
  at chunks/nitro/nitro.mjs:1:68337 in createError$1
  at chunks/nitro/nitro.mjs:1:489180 in hubDatabase
  at chunks/nitro/nitro.mjs:1:500032
------------------------------
- Operating System: Darwin
- Node Version:     v21.7.3
- Nuxt Version:     3.14.0
- CLI Version:      3.15.0
- Nitro Version:    2.10.2
- Package Manager:  [email protected]
- Builder:          -
- User Config:      default
- Runtime Modules:  @nuxthub/[email protected], @nuxt/[email protected], @nuxt/[email protected], @nuxt/ui, @vueuse/[email protected], @nuxtjs/[email protected], [email protected], [email protected]
- Build Modules:    -
------------------------------

@atinux
Copy link
Contributor

atinux commented Nov 4, 2024

How do you deploy your app @aligzl ?

@aligzl
Copy link
Author

aligzl commented Nov 4, 2024

How do you deploy your app @aligzl ?

trough github actions

@aligzl
Copy link
Author

aligzl commented Nov 5, 2024

Hi @atinux
Have you managed to find the issue? as i cant baypass anymore within downgrading.

Copy link
Contributor

atinux commented Nov 6, 2024

Do you mind inviting me to your project? Did you change anything in the bindings of your project on Cloudflare?

@aligzl
Copy link
Author

aligzl commented Nov 6, 2024

Do you mind inviting me to your project? Did you change anything in the bindings of your project on Cloudflare?

I have invited you to my project and i did not touch anything in the bindings

@atinux
Copy link
Contributor

atinux commented Nov 6, 2024

I found the issue @aligzl

You should not call hubDatabase() or hubKV() inside the server/utils/ without wrapping them into a function:

- export const todoDb = new todoService(hubDatabase())
+ export const todoDb = () => new todoService(hubDatabase())

You will need to update todoDb.findOneAndUpdate to todoDb().findOneAndUpdate for example.

This is because the bindings are available only when the request comes in, so inside the event handlers, before this, they are not ready, thus the error happening (I believe Cloudflare try to run the code before deploying it).

@atinux atinux added the question Further information is requested label Nov 6, 2024
@aligzl
Copy link
Author

aligzl commented Nov 6, 2024

I found the issue @aligzl

You should not call hubDatabase() or hubKV() inside the server/utils/ without wrapping them into a function:

- export const todoDb = new todoService(hubDatabase())
+ export const todoDb = () => new todoService(hubDatabase())

You will need to update todoDb.findOneAndUpdate to todoDb().findOneAndUpdate for example.

This is because the bindings are available only when the request comes in, so inside the event handlers, before this, they are not ready, thus the error happening (I believe Cloudflare try to run the code before deploying it).

let me try,
But it was working before

Thanks for your kind help

Copy link
Contributor

atinux commented Nov 6, 2024

It was an issue if it was working before I believe, it was probably related to how the chunks were generated with Nitro.

@aligzl
Copy link
Author

aligzl commented Nov 6, 2024

It works as expected now
i think it's a good point to add it to the docs to avoid this kind of mistakes or approaches

Thanks

@aligzl aligzl closed this as completed Nov 6, 2024
Copy link
Contributor

atinux commented Nov 6, 2024

Where do you think would be the best place?

@Nicholaiii
Copy link

Where do you think would be the best place?
Near examples of how hubDatabase is used, perhaps

I ran in to this issue when setting up the Drizzle ORM example, thinking it was wasteful to create a new database connection every time.
{45640C58-59E2-46C4-901B-11AE07D76AA6}

The error does not seem to be handled properly:
{E8E6A486-A606-49FC-93BC-70587C907118}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants