当我尝试在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>
3条答案
按热度按时间bpsygsoo1#
我也遇到了这个问题(使用Windows)。很难创建
package.json
-因为它没有出现在npm init
之后。阻止我能够安装npm包。它帮助我:
以获得实际有效的package.json。
7z5jn7bk2#
此错误表示您没有将package.json文件复制到输出文件夹。
如果您使用的是Typescript -更新tsconfig.json,包括:[“软件包. json”]
如果您使用的是Js或任何构建工具-使用任何shell脚本复制文件。
您还可以在package.json中使用值为
安装包〉
npm install copyfiles
更新脚本节
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上不行,我正在调查。