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

Unable to use fetch API on Azure Static web apps #2676

Open
censujiang opened this issue Aug 20, 2024 · 7 comments
Open

Unable to use fetch API on Azure Static web apps #2676

censujiang opened this issue Aug 20, 2024 · 7 comments

Comments

@censujiang
Copy link

censujiang commented Aug 20, 2024

Environment

node:20 in azure static web apps

Reproduction

https://stackblitz.com/edit/github-p3avvp?file=server%2Froutes%2Findex.ts

Describe the bug

In this product environment of Azure, even if it is set to node:20, it still does not include the fetch api

nuxt/nuxt#28611

Additional context

A valid Azure subscription is required to test Static web apps. This error only occurs in the cloud, not in the local simulator.

Logs

{
    "url": "/",
    "statusCode": 500,
    "statusMessage": "",
    "message": "[GET] \"https://www.baidu.com\": <no response> _fetch1 is not a function",
    "stack": ""
}
### Tasks
@itpropro
Copy link
Contributor

itpropro commented Oct 1, 2024

When using the exact example from the docs, it also works

export default defineEventHandler(async (event) => {
  const data = await $fetch('https://ungh.cc/orgs/unjs/repos');
  return data;
});

image

When using ofetch directly it works

import { $fetch } from 'ofetch';
export default defineEventHandler(async (event) => {
  return await $fetch('https://unjs.io/');
});

image

I configured preset: 'azure' and executed build. The artifacts were then deployed using swa deploy .\.output\public\ --api-location .\.output\server\ --deployment-token TOKEN --api-language "node" --api-version "20" --env production.

I think you are not using fetch correct, as your reproduction already fails in stackblitz. Please check the docs about native fetch:
https://nitro.unjs.io/guide/fetch

EDIT: Changed ordering of examples to make it more clear.

@pi0
Copy link
Member

pi0 commented Oct 1, 2024

$fetch (same as fetch) should work in every file without any import, this seems like a bug (but harder to reproduce, as rollup sometimes mess up with chunk orders in more complex builds)

@itpropro by your testing, if you avoid import, do you reproduce issue or not?

@censujiang
Copy link
Author

$fetch (same as fetch) should work in every file without any import, this seems like a bug (but harder to reproduce, as rollup sometimes mess up with chunk orders in more complex builds)

@itpropro by your testing, if you avoid import, do you reproduce issue or not?

It could also be a fetch keyword error caused by a packaging issue, but I may have time to track this down later

@itpropro
Copy link
Contributor

itpropro commented Oct 2, 2024

$fetch (same as fetch) should work in every file without any import, this seems like a bug (but harder to reproduce, as rollup sometimes mess up with chunk orders in more complex builds)

@itpropro by your testing, if you avoid import, do you reproduce issue or not?

The second version I tested was without any imports, the ofetch one was only for the sake of testing, I should have ordered them the other way around. Both work in Static Web Apps.

@pi0
Copy link
Member

pi0 commented Oct 2, 2024

Okay, then it is most certainly a rollup chunk ordering issue.

@censujiang If can still reproduce, do you think you can share a public repository? (Nuxt setup is also acceptable in this case since it might be also needed for reproduction)

If it is not reproducible anymore I would suggest closing the issue in the meanwhile.

@censujiang
Copy link
Author

Okay, then it is most certainly a rollup chunk ordering issue.

@censujiang If can still reproduce, do you think you can share a public repository? (Nuxt setup is also acceptable in this case since it might be also needed for reproduction)

If it is not reproducible anymore I would suggest closing the issue in the meanwhile.

I'd like to provide a Nuxt/Nitro repository that can be used for reproduction, but I'm currently on the Chinese National Day public holiday, so it's not convenient for now. I'll talk about it after the holiday.

@pi0
Copy link
Member

pi0 commented Oct 2, 2024

No hurry thanks @censujiang!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants