gpt4 book ai didi

node.js - 无法在Azure应用程序服务上部署React JS应用程序

转载 作者:行者123 更新时间:2023-12-02 05:54:00 27 4
gpt4 key购买 nike

我正在浏览一些在 azure 应用程序服务上部署 React Js 应用程序的链接。但我在部署应用程序时遇到一些问题。

我已将所有必要的内容(例如 web.config 文件)添加到 public 文件夹中,并将构建目录添加到工作区。

Deploying web app on azure app service

Deploy Node.js to Azure App Service using Visual Studio Code

遵循了所有步骤,但当我尝试在 azure 应用程序服务上部署时出现以下错误。在部署之前我会运行这些命令

npm run build

2020-08-19T10:44:45.762075166Z A P P   S E R V I C E   O N   L I N U X
2020-08-19T10:44:45.762079567Z
2020-08-19T10:44:45.762083667Z Documentation: http://aka.ms/webapp-linux
2020-08-19T10:44:45.762088167Z NodeJS quickstart: https://aka.ms/node-qs
2020-08-19T10:44:45.762092268Z NodeJS Version : v12.16.3
2020-08-19T10:44:45.762096468Z Note: Any data outside '/home' is not persisted
2020-08-19T10:44:45.762100768Z
2020-08-19T10:44:45.789282727Z Found build manifest file at '/home/site/wwwroot/oryx-manifest.toml'. Deserializing it...
2020-08-19T10:44:45.792738514Z Build Operation ID: |OtQwveNuO0A=.83a2ec6c_
2020-08-19T10:44:47.255197638Z Writing output script to '/opt/startup/startup.sh'
2020-08-19T10:44:47.960307930Z Running #!/bin/sh
2020-08-19T10:44:47.960336532Z
2020-08-19T10:44:47.960345833Z # Enter the source directory to make sure the script runs where the user expects
2020-08-19T10:44:47.960355334Z cd "/home/site/wwwroot"
2020-08-19T10:44:47.960363235Z
2020-08-19T10:44:47.960370735Z export NODE_PATH=$(npm root --quiet -g):$NODE_PATH
2020-08-19T10:44:47.960378436Z if [ -z "$PORT" ]; then
2020-08-19T10:44:47.960386136Z export PORT=8080
2020-08-19T10:44:47.960393937Z fi
2020-08-19T10:44:47.960401238Z
2020-08-19T10:44:47.960408638Z echo Found tar.gz based node_modules.
2020-08-19T10:44:47.960416339Z extractionCommand="tar -xzf node_modules.tar.gz -C /node_modules"
2020-08-19T10:44:47.960424040Z echo "Removing existing modules directory from root..."
2020-08-19T10:44:47.960431740Z rm -fr /node_modules
2020-08-19T10:44:47.960439141Z mkdir -p /node_modules
2020-08-19T10:44:47.960446542Z echo Extracting modules...
2020-08-19T10:44:47.960453842Z $extractionCommand
2020-08-19T10:44:47.960461243Z export NODE_PATH="/node_modules":$NODE_PATH
2020-08-19T10:44:47.960468943Z export PATH=/node_modules/.bin:$PATH
2020-08-19T10:44:47.960476344Z if [ -d node_modules ]; then
2020-08-19T10:44:47.960483745Z mv -f node_modules _del_node_modules || true
2020-08-19T10:44:47.960491245Z fi
2020-08-19T10:44:47.960498446Z
2020-08-19T10:44:47.960505546Z if [ -d /node_modules ]; then
2020-08-19T10:44:47.960524748Z ln -sfn /node_modules ./node_modules
2020-08-19T10:44:47.960532849Z fi
2020-08-19T10:44:47.960540149Z
2020-08-19T10:44:47.960547550Z echo "Done."
2020-08-19T10:44:47.960554951Z npm start
2020-08-19T10:44:48.258132115Z Found tar.gz based node_modules.
2020-08-19T10:44:48.258154316Z Removing existing modules directory from root...
2020-08-19T10:44:48.260461807Z Extracting modules...
2020-08-19T10:44:48.262765098Z tar (child): node_modules.tar.gz: Cannot open: No such file or directory
2020-08-19T10:44:48.262778299Z tar (child): Error is not recoverable: exiting now
2020-08-19T10:44:48.262970515Z tar: Child returned status 2
2020-08-19T10:44:48.262983816Z tar: Error is not recoverable: exiting now
2020-08-19T10:44:48.290740216Z Done.
2020-08-19T10:44:48.512406278Z npm info it worked if it ends with ok
2020-08-19T10:44:48.512836614Z npm info using <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5b352b361b6d756a6f756f" rel="noreferrer noopener nofollow">[email protected]</a>
2020-08-19T10:44:48.512976126Z npm info using <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="721c1d1617320443405c43445c41" rel="noreferrer noopener nofollow">[email protected]</a>
2020-08-19T10:44:48.578204629Z npm info lifecycle <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9cfdf8fdf0c3fdecececdcacb2adb2ac" rel="noreferrer noopener nofollow">[email protected]</a>~prestart: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="98f9fcf9f4c7f9e8e8e8d8a8b6a9b6a8" rel="noreferrer noopener nofollow">[email protected]</a>
2020-08-19T10:44:48.584464048Z npm info lifecycle <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="15747174794a7465656555253b243b25" rel="noreferrer noopener nofollow">[email protected]</a>~start: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="94f5f0f5f8cbf5e4e4e4d4a4baa5baa4" rel="noreferrer noopener nofollow">[email protected]</a>
2020-08-19T10:44:48.589867495Z
2020-08-19T10:44:48.589881796Z > <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9afbfefbf6c5fbeaeaeadaaab4abb4aa" rel="noreferrer noopener nofollow">[email protected]</a> start /home/site/wwwroot
2020-08-19T10:44:48.589887297Z > react-scripts start
2020-08-19T10:44:48.589891697Z
2020-08-19T10:44:48.597331914Z sh: 1: react-scripts: not found
2020-08-19T10:44:48.598224588Z npm info lifecycle <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bcddd8ddd0e3ddccccccfc8c928d928c" rel="noreferrer noopener nofollow">[email protected]</a>~start: Failed to exec start script
2020-08-19T10:44:48.599091959Z npm ERR! code ELIFECYCLE
2020-08-19T10:44:48.599182267Z npm ERR! syscall spawn
2020-08-19T10:44:48.599258573Z npm ERR! file sh
2020-08-19T10:44:48.599314678Z npm ERR! errno ENOENT
2020-08-19T10:44:48.600738196Z npm ERR! <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ec8d888d80b38d9c9c9cacdcc2ddc2dc" rel="noreferrer noopener nofollow">[email protected]</a> start: `react-scripts start`
2020-08-19T10:44:48.600749897Z npm ERR! spawn ENOENT
2020-08-19T10:44:48.600754497Z npm ERR!
2020-08-19T10:44:48.600758798Z npm ERR! Failed at the <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c7a6a3a6ab98a6b7b7b787f7e9f6e9f7" rel="noreferrer noopener nofollow">[email protected]</a> start script.
2020-08-19T10:44:48.600763398Z npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-08-19T10:44:48.605436585Z npm timing npm Completed in 125ms
2020-08-19T10:44:48.605621800Z
2020-08-19T10:44:48.605672405Z npm ERR! A complete log of this run can be found in:
2020-08-19T10:44:48.605750311Z npm ERR! /root/.npm/_logs/2020-08-19T10_44_48_601Z-debug.log

但问题是同一个应用程序可以使用以下命令在本地完美运行npm installnpm start

只是为了验证 npm run build 后生成的构建是否有效尝试使用以下命令从构建目录运行应用程序

npm install -g serve

然后

serve -s build

然后应用程序在浏览器中打开。

最佳答案

做了一些谷歌搜索后found solution 。我们需要在 Linux 机器的应用服务配置的启动命令中添加以下命令。

pm2 服务/home/site/wwwroot --no-daemon

步骤:

- Go to App Service

- Navigate to Configuration

- Click on General Settings

- add the above command in Start up command, click on save

- then restart the server

关于node.js - 无法在Azure应用程序服务上部署React JS应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63485396/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com