Azure部署:站点/wwwroot中没有package.json文件

1l5u6lss  于 2023-02-25  发布在  其他
关注(0)|答案(3)|浏览(166)

当我尝试在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似乎运行成功,创建了一个填充/site/wwwroot文件夹的build文件夹。但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>
bpsygsoo

bpsygsoo1#

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

type NUL > package.json
npm init -f

以获得实际有效的package.json。

    • 在Azure门户中创建函数应用程序时遇到问题**
7z5jn7bk

7z5jn7bk2#

此错误表示您没有将package.json文件复制到输出文件夹。
如果您使用的是Typescript -更新tsconfig.json,包括:[“软件包. json”]
如果您使用的是Js或任何构建工具-使用任何shell脚本复制文件。
您还可以在package.json中使用值为
安装包〉npm install copyfiles
更新脚本节

"postbuild": "npx copyfiles -u 1 ./src/**/*.json ./dist -V"
cedebl8k

cedebl8k3#

    • 更新日期:**

转到https://[yourappname].scm.azurewebsites.net/webssh/host并运行npm install -g npm,然后在home/site/wwwroot下运行npm init命令。

    • 原始答复:**

您是否选择Linux作为Web应用程序的操作系统?我在Linux上遇到了类似的问题,但在Windows操作系统上不会发生。
理论上没有package.json,用npm init创建就行了,我在Windows OS上可以流畅运行,但在Linux上不行,我正在调查。

相关问题