Azure functions not working
See https://github.com/unjs/nitro-deploys/issues/48 and https://github.com/unjs/nitro/pull/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:
- https://github.com/unjs/nitro/blob/main/src/runtime/entries/azure.ts
- https://github.com/unjs/nitro/blob/main/src/presets/azure.ts
azure fns:
- https://github.com/unjs/nitro/blob/main/src/runtime/entries/azure-functions.ts
- https://github.com/unjs/nitro/blob/main/src/presets/azure-functions.ts
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:
Also notably it says in the Next.JS hybrid rendering docs the following:
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.:
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 https://github.com/microsoft/Oryx/issues/2340 https://github.com/microsoft/Oryx/issues/1150#issuecomment-1886067023)
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.
Thanks for all your investigations! Just to double check, have you tried the shamefully-hoist: true flag in .npmrc?
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.
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?
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?
With noExternals and a vanialla Docus site built with NPM I seem to get this error:
@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.
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)
(corepack enable might also do the trick)
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.)
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.
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