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

Azure functions not working #2114

Closed
pi0 opened this issue Jan 23, 2024 · 12 comments · Fixed by #2769
Closed

Azure functions not working #2114

pi0 opened this issue Jan 23, 2024 · 12 comments · Fixed by #2769

Comments

@pi0
Copy link
Member

pi0 commented Jan 23, 2024

See nitrojs/nitro-deploys#48 and #2092 for some context.

Unfrounatly i don't have any more information what exactly is the issue nor had a chance to investigate. So here is a placeholder.🤷‍♂️


(ref) all magic we have for azure support:

azure swa:

azure fns:

@GerryWilko
Copy link
Contributor

GerryWilko commented Jan 24, 2024

I have done a bit of investigation and this appears to be perhaps at least partially related to using pnpm or anything but npm.

Reading the Azure Static Web Apps docs carefully it says this:

Screenshot 2024-01-24 at 16 48 19

Also notably it says in the Next.JS hybrid rendering docs the following:

Screenshot 2024-01-24 at 16 49 38

I'm going to take a small leap here and suggest that this note should also be on the nuxt docs. It appears that Microsoft's GitHub and Azure Pipelines does more than just build our applications it also appears to modify parts of it.

I have two built outputs one from the SWA CLI from the GitHub task and one I built locally. They have some significant differences in various files e.g.:

image image

Ouputs:
outputs.zip

I'm not totally sure but I presume these are transforms added by the SWA CLI. Therefore if you are not using the SWA CLI to build your application you do not get these changes applied to the built output.

At present Microsoft's Oryx builder does not support pnpm or other package managers and it doesn't look like support will be coming any time soon 😞 (see microsoft/Oryx#2340 microsoft/Oryx#1150 (comment))

I believe the Nitro docs should be updated to clarify that at present the Azure preset only works with npm as a package manager. It also makes it quite tricky to support any monorepos (my solution is a mono repo) as you have limited control over the build steps in the SWA cli.

@pi0
Copy link
Member Author

pi0 commented Jan 24, 2024

Thanks for all your investigations! Just to double check, have you tried the shamefully-hoist: true flag in .npmrc?

@GerryWilko
Copy link
Contributor

Yep this is set in the .npmrc file. Also I can replicate the same issues using npm by building locally with npm and then deploying the outpuit straight to Azure without using the SWA CLI and the same 404 behaviour occurs.

The outputs.zip file above are both built using npm as the package manager. The only difference is that SWA CLI built one of them. And the differences are shown in the screenshots.

I probably shouldn't have said its related to pnpm because its not really. Its just that you must let the SWA CLI build your project. The reason this may be pertinent to pnpm users is that SWA CLI can only build projects that use npm as a package manager.

@GerryWilko
Copy link
Contributor

The other thing to mention is that as it stands the docs for the average nuxt application will work. Except it does potentially cause issues as users may not realise that when it deploys the pacakage manager being used to build is npm which may not be the one they expected.

This means their lock files aren't neccesarily respected so could cause some unexpected behaviour when deployed.

It probably just needs a similar warning on the Azure preset to note that this only works with npm at present. Shall I raise a small PR?

@pi0
Copy link
Member Author

pi0 commented Jan 24, 2024

Okay, i think we are on a much better track. If you can confirm both presets work only with npm only, sure that would be more helpful to people I guess. Feel free to make PR 👍🏼

At the same time, this seems interesting. I am suspicious we might be doing something in nitro, external tracer that they don't like or support. Do you have a chance to try noExternals: true option if it makes any different?

@GerryWilko
Copy link
Contributor

With noExternals and a vanialla Docus site built with NPM I seem to get this error:
image

@pi0
Copy link
Member Author

pi0 commented Jan 25, 2024

@GerryWilko Would you please use only Nitro (preferably) or Nuxt? Docus is not maintained and could be source of false positive results in our case.

@itpropro
Copy link
Contributor

itpropro commented Jan 25, 2024

Have you tried adding this to your Build and Deploy action if you are using pnpm?

env:
          PRE_BUILD_COMMAND: npm install -g pnpm
          CUSTOM_BUILD_COMMAND: pnpm install && pnpm run build
          NODE_VERSION: 18.17.1 (or any other one)

@pi0
Copy link
Member Author

pi0 commented Jan 25, 2024

(corepack enable might also do the trick)

@danielroe
Copy link
Member

danielroe commented Jan 31, 2024

Testing, Azure SWA works fine as documented on currently released nitro version but fails with nitro nightly release (h3 is irrelevant for this). (Still checking though.)

@danielroe
Copy link
Member

Update: the underlying code works fine; the issue is that the code includes imports from nitropack/dist/runtime/plugin which is not present as the traced files only contain nitropack-nightly. Not clear why this affects azure more than any other preset.

@itpropro
Copy link
Contributor

itpropro commented Oct 2, 2024

Azure Functions is actually not working for most cases where azure libraries are used, as the zip packaging currently doesn't follow symlinks.
Just as a reference for people wanting to use Azure Functions with pnpm, you should have at least these two entries in your .npmrc:

shamefully-hoist=true
node-linker=hoisted

The zip bundle not containing the correct files will be fixed with #2769

pi0 pushed a commit that referenced this issue Oct 2, 2024
@pi0 pi0 closed this as completed in #2769 Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants