gpt4 book ai didi

node.js - site/wwwroot 中的 Azure 部署 : no package. json 文件

转载 作者:太空宇宙 更新时间:2023-11-04 01:20:15 25 4
gpt4 key购买 nike

当我尝试在 Chrome 中打开 Azure NodeJS React Web 应用程序时,出现以下错误:

PATH="$PATH:/home/site/wwwroot" npm start
ENOENT: no such file or directory, open '/home/site/wwwroot/package.json

当我检查 Azure SSH 中/site/wwwroot 的内容时,会进行检查:

_del_node_modules
asset-manifest.json
b
favicon.ico
index.html
logo192.png
logo512.png
manifest.json
oryx-appinsightsloader.js
package-lock.json
precache-manifest.6794c2e4defba13a31dcee7cae67859b.js
precache-manifest.705c77ad34ded94d21baca064fa569aa.js
precache-manifest.730dd540546e78da1c3ebb04036e733d.js
precache-manifest.9980bb9186e0ebd2771eff926887f432.js
precache-manifest.9a518a34a27fad9a357b7c78cdfbb7e8.js
precache-manifest.9c65ce33aab3813a0f162cf91b74c0f4.js
precache-manifest.ac183c8385a56a732a8286d5f2d8fa64.js
precache-manifest.b8756a719b957537ff5eb2ede103962d.js
precache-manifest.cbb7b5b3cc0bfbf94c161143ff651d3b.js
precache-manifest.e58827ccfca6115bc9268d09a7361ddd.js
robots.txt
service-worker.js
static
web.config

我在 Azure 上的构建管道从根目录运行 npm install 和 npm run build,在 VScode 中运行时成功。管道和发布成功。 VScode 中目录树的外部结构如下所示:

├── README.md
├── node_modules
├── package-lock.json
├── package.json
├── public
├── schema.sql
├── server
└── src

因此,npm run build 似乎已成功运行,创建了一个 build 文件夹来填充 /site/wwwroot 文件夹。但 Azure 需要一个 package.json 文件。我尝试在 VScode 的 public 文件夹中运行 npm init ,还尝试将 npm init 添加到 Azure 管道构建任务中,但得到的结果相同错误。

另外,不确定这是否相关,但我在 public 文件夹中添加了一个 web.config 文件。当我在 Azure SSH 中查看该文件时,它看起来无法正确读取:

/home/site/wwwroot/web.config: line 1: !--: No such file or directory
/home/site/wwwroot/web.config: line 2: $'\r': command not found
/home/site/wwwroot/web.config: line 3: ?xml: No such file or directory
/home/site/wwwroot/web.config: line 4: configuration: No such file or directory
/home/site/wwwroot/web.config: line 5: system.webServer: No such file or directory
/home/site/wwwroot/web.config: line 6: handlers: No such file or directory
/home/site/wwwroot/web.config: line 7: add: No such file or directory
/home/site/wwwroot/web.config: line 8: /handlers: No such file or directory
/home/site/wwwroot/web.config: line 9: rewrite: No such file or directory
/home/site/wwwroot/web.config: line 10: rules: No such file or directory
/home/site/wwwroot/web.config: line 11: rule: No such file or directory
/home/site/wwwroot/web.config: line 12: match: No such file or directory
/home/site/wwwroot/web.config: line 13: action: No such file or directory
/home/site/wwwroot/web.config: line 14: /rule: No such file or directory
/home/site/wwwroot/web.config: line 15: rule: No such file or directory
/home/site/wwwroot/web.config: line 16: match: No such file or directory
/home/site/wwwroot/web.config: line 17: conditions: No such file or directory
/home/site/wwwroot/web.config: line 18: add: No such file or directory
/home/site/wwwroot/web.config: line 19: add: No such file or directory
/home/site/wwwroot/web.config: line 20: add: No such file or directory
/home/site/wwwroot/web.config: line 21: /conditions: No such file or directory
/home/site/wwwroot/web.config: line 22: action: No such file or directory
/home/site/wwwroot/web.config: line 23: /rule: No such file or directory
/home/site/wwwroot/web.config: line 24: /rules: No such file or directory
/home/site/wwwroot/web.config: line 25: /rewrite: No such file or directory
/home/site/wwwroot/web.config: line 26: /system.webServer: No such file or directory
/home/site/wwwroot/web.config: line 27: syntax error near unexpected token `newline'
/home/site/wwwroot/web.config: line 27: `</configuration>'

这是 VScode 中的样子:

<!-- tells azure to rewrite all urls as if they are pointing to root file-->

<?xml version="1.0"?>
<configuration>
<system.webServer>
<handlers>
<add name="iisnode" path="index.js" verb="*" modules="iisnode"/>
</handlers>
<rewrite>
<rules>
<rule name="DynamicContent">
<match url="/*" />
<action type="Rewrite" url="index.js"/>
</rule>
<rule name="React Routes" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

最佳答案

我也遇到这个问题(使用windows)。创建 package.json 很困难 - 因为它在 npm init 之后没有出现。阻止我安装 npm 包。

它帮助我:

type NUL > package.json
npm init -f

获取实际有效的 package.json。

我在 Azure 门户中创建 Functions 应用程序时遇到问题

关于node.js - site/wwwroot 中的 Azure 部署 : no package. json 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59556755/

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