通过 Github 在 Azure Webapp 服务上的 React 应用程序失败并显示 MODULE_NOT_FOUND

问题描述 投票:0回答:1

我有一个 React 应用程序,它在本地运行得非常好。

我创建了 Azure Web App 并配置了包含 React js 代码的 GitHub 存储库。构建和部署都很顺利,虽然花费了近 2 个小时。

部署后,我注意到它失败并出现 MODULE_NOT_FOUND 错误。

我在 package.json 的脚本部分尝试了以下两个版本

  1. “开始”:“反应脚本开始”,
  2. “开始”:“/home/site/wwwroot/node_modules/.bin/react-scripts开始”,

错误日志:

2023-08-26T21:22:06.717089653Z    _____                               
2023-08-26T21:22:06.717127133Z   /  _  \ __________ _________   ____  
2023-08-26T21:22:06.717136631Z  /  /_\  \\___   /  |  \_  __ \_/ __ \ 
2023-08-26T21:22:06.717140979Z /    |    \/    /|  |  /|  | \/\  ___/ 
2023-08-26T21:22:06.717145377Z \____|__  /_____ \____/ |__|    \___  >
2023-08-26T21:22:06.717149796Z         \/      \/                  \/ 
2023-08-26T21:22:06.717153343Z A P P   S E R V I C E   O N   L I N U X
2023-08-26T21:22:06.717156809Z 
2023-08-26T21:22:06.717160115Z Documentation: http://aka.ms/webapp-linux
2023-08-26T21:22:06.717161989Z NodeJS quickstart: https://aka.ms/node-qs
2023-08-26T21:22:06.717163812Z NodeJS Version : v18.16.1
2023-08-26T21:22:06.717165585Z Note: Any data outside '/home' is not persisted
2023-08-26T21:22:06.717167419Z 
2023-08-26T21:22:07.244829379Z Starting OpenBSD Secure Shell server: sshd.
2023-08-26T21:22:07.394588279Z Starting periodic command scheduler: cron.
2023-08-26T21:22:07.609497822Z Could not find build manifest file at '/home/site/wwwroot/oryx-manifest.toml'
2023-08-26T21:22:07.609529071Z Could not find operation ID in manifest. Generating an operation id...
2023-08-26T21:22:07.609535893Z Build Operation ID: f88a9047-884b-4267-95d9-2085b8a5e06d
2023-08-26T21:22:07.828483725Z Environment Variables for Application Insight's IPA Codeless Configuration exists..
2023-08-26T21:22:07.867662678Z Writing output script to '/opt/startup/startup.sh'
2023-08-26T21:22:07.928152795Z Running #!/bin/sh
2023-08-26T21:22:07.928182200Z 
2023-08-26T21:22:07.928189413Z # Enter the source directory to make sure the script runs where the user expects
2023-08-26T21:22:07.928216364Z cd "/home/site/wwwroot"
2023-08-26T21:22:07.928221193Z 
2023-08-26T21:22:07.928225651Z export NODE_PATH=/usr/local/lib/node_modules:$NODE_PATH
2023-08-26T21:22:07.928230240Z if [ -z "$PORT" ]; then
2023-08-26T21:22:07.928234648Z      export PORT=8080
2023-08-26T21:22:07.928238776Z fi
2023-08-26T21:22:07.928242313Z 
2023-08-26T21:22:07.928245759Z npm start
2023-08-26T21:22:15.473095058Z npm info using [email protected]
2023-08-26T21:22:15.476135731Z npm info using [email protected]
2023-08-26T21:22:15.769149040Z 
2023-08-26T21:22:15.769177904Z > [email protected] start
2023-08-26T21:22:15.769185007Z > react-scripts start
2023-08-26T21:22:15.769190357Z 
2023-08-26T21:22:15.996996292Z node:internal/modules/cjs/loader:1080
2023-08-26T21:22:15.997126006Z   throw err;
2023-08-26T21:22:15.997133580Z   ^
2023-08-26T21:22:15.997149409Z 
2023-08-26T21:22:15.997153848Z Error: Cannot find module '../scripts/start'
2023-08-26T21:22:15.997157745Z Require stack:
2023-08-26T21:22:15.997161462Z - /home/site/wwwroot/node_modules/.bin/react-scripts
2023-08-26T21:22:15.997165089Z     at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)
2023-08-26T21:22:15.997168856Z     at Function.resolve (node:internal/modules/cjs/helpers:116:19)
2023-08-26T21:22:15.997172342Z     at Object.<anonymous> (/home/site/wwwroot/node_modules/.bin/react-scripts:31:23)
2023-08-26T21:22:15.997176330Z     at Module._compile (node:internal/modules/cjs/loader:1256:14)
2023-08-26T21:22:15.997179646Z     at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
2023-08-26T21:22:15.997183453Z     at Module.load (node:internal/modules/cjs/loader:1119:32)
2023-08-26T21:22:15.997187000Z     at Module._load (node:internal/modules/cjs/loader:960:12)
2023-08-26T21:22:15.997190606Z     at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
2023-08-26T21:22:15.997193993Z     at node:internal/main/run_main_module:23:47 {
2023-08-26T21:22:15.997197509Z   code: 'MODULE_NOT_FOUND',
2023-08-26T21:22:15.997201337Z   requireStack: [ '/home/site/wwwroot/node_modules/.bin/react-scripts' ]
2023-08-26T21:22:15.997205474Z }
2023-08-26T21:22:15.997768208Z 
2023-08-26T21:22:15.997777886Z Node.js v18.16.1
reactjs azure web-applications modulenotfounderror
1个回答
0
投票

我假设您已经构建(使用像

yarn build
这样的命令)并在Linux模式下的azure应用程序服务中部署了该应用程序。

您现在需要做的就是将以下脚本添加为 Azure Web 应用程序配置 -> 常规设置选项卡中的启动命令:

pm2 serve /home/site/wwwroot --spa --no-daemon

示例:

查看 Azure 的文档:https://learn.microsoft.com/en-us/azure/app-service/configure-language-nodejs?pivots=platform-linux

© www.soinside.com 2019 - 2024. All rights reserved.