Azure / static-web-apps

Azure Static Web Apps. For bugs and feature requests, please create an issue in this repo. For community discussions, latest updates, kindly refer to the Discussions Tab. To know what's new in Static Web Apps, visit https://aka.ms/swa/ThisMonth
https://aka.ms/swa
MIT License
330 stars 57 forks source link

Deployment to existing static app failed updating node.js version. #283

Closed stemixreal closed 3 years ago

stemixreal commented 3 years ago

Hi Folks,

I have a static web app and have recently added additional functions to /api to enable me to use cosmos db. After adding and testing the functionality locally I deployed the changes.

The deployment failed with the following Oryx errors

Detecting platforms... Detected following platforms: nodejs: 14.15.1 Version '14.15.1' of platform 'nodejs' is not installed. Generating script to install it...

Error: Could not find either 'build' or 'build:azure' node under 'scripts' in package.json. Could not find value for custom run build command using the environment variable key 'RUN_BUILD_COMMAND'.Could not find tools for building monorepos, no 'lerna.json' or 'lage.config.js' files found.

---End of Oryx build logs

Oryx could not find a 'build' or 'build:azure' script in the package configuration. Please add one of these commands to your package configuration file (i.e. package.json). Alternatively, you can add the app_build_command to the build/deploy configuration section of your workflow file. For example, app_build_command: 'npm run docs:build'

...

image


I've had a look around and found:

https://github.com/microsoft/Oryx/issues/891

but as everything has worked without issue in deployment so far I haven't really looked into Oryx/Actions in any great detail so I don't know if the fix is something I can use for static web apps. Where would I apply the suggested workaround if it is possible? I can't see anything in the workflow yaml that gives me any clues. The solution is for an app service hosted function.

https://github.com/microsoft/Oryx/issues/891#issuecomment-756147542

Any pointers greatly appreciated. Cheers Steve

monksudo commented 3 years ago

Same issue for me as well.

stemixreal commented 3 years ago

I'm finding my way with this but adding

- uses: actions/setup-node@v2 with: node-version: 14

produces

Run actions/setup-node@v2 with: node-version: 14 always-auth: false check-latest: false token: * Found in cache @ /opt/hostedtoolcache/node/14.15.4/x64**

Adding

_- run: npm install

fails with the error that package.json doesn't exist in the root of the app as indicated in a roundabout way in the original second error.

I've installed the node modules in /api and package.json was created there automatically. Do I need a copy in the root too/in place of? I've have tried that but no luck. Same error. So I'm missing something obviously.

Should my build process even be trying to install Node? It doesn't appear so. This began after I added Cosmos DB for Azure tables Javascript libraries.

stemixreal commented 3 years ago

Ok I think I've sorted this out. At least, everything builds though there were a couple of errors during the build they don't break the build - missing descriptions and the like.

@monksudo, there were superfluous package files in my root (an oversight on my part). Once I deleted those the app deploys ok. I deleted both package.json & package-lock.json which caused the build process to try to install node in the root which is unwanted and impossible anyway it seems.

anthonychu commented 3 years ago

@stemixreal If you can share a repo that reproduces the original problem, happy to take a look to see if there's anything we can do to make this experience better.

stemixreal commented 3 years ago

Hi Anthony, thanks. The error was mine. I mistakenly installed all the node packages in the web root initially and neglected to deleted the node_modules folder from there. I didn't notice it among other files and folders to be honest. So even though I then installed things correctly, the build was trying to install node in the SWA root.

The repo is private but happy to send an invite. It's just a static web app with some signalr hub and cosmos db tests for a game I'm working on.

I guess I must have broken something when fiddling about though. I'm getting internal server errors from the function that was working. No worries though. It's no problem to take a couple of steps back.

appasaheb4 commented 3 years ago
Screenshot 2021-05-04 at 8 40 49 AM

same issue facing

jrathgeber commented 2 years ago

Same error. Deleting package-lock.json fixed it. Thank you !

Serge-N commented 1 year ago

If this is still an issue for some developers. You may be facing at one of the following issues: