如何成功将React应用程序部署到Azure

时间:2019-10-16 04:45:44

标签: .net reactjs azure npm

我正在构建一个React .NET Core应用程序。本地构建良好,但是在Azure中,构建的React / npm部分失败。下方:

> melanies_site@0.1.0 build D:\home\site\repository\ClientApp
remote:   > react-scripts build
remote:   
remote:   'react-scripts' is not recognized as an internal or external command,
remote:   operable program or batch file.
remote:   
remote:   npm ERR! melanies_site@0.1.0 build: `react-scripts build`
remote:   npm ERR! Exit status 1
remote:   npm ERR! 
remote:   npm ERR! Failed at the melanies_site@0.1.0 build script.
remote:   npm ERR! This is most likely a problem with the melanies_site package,
remote:   npm ERR! not with npm itself.
remote:   npm ERR! Tell the author that this fails on your system:
remote:   npm ERR!     react-scripts build
remote:   npm ERR! You can get their info via:
remote:   npm ERR!     npm owner ls melanies_site
remote:   npm ERR! There is likely additional logging output above.
remote:   npm ERR! System Windows_NT 6.2.9200
remote:   npm ERR! command "node" "D:\\Program Files (x86)\\npm\\1.4.28\\node_modules\\npm\\bin\\npm-cli.js" "run" "build"
remote:   npm ERR! cwd D:\home\site\repository\ClientApp
remote:   npm ERR! node -v v0.10.40
remote:   npm ERR! npm -v 1.4.28
remote:   npm ERR! code ELIFECYCLE

package.json:

{
    "name": "melanies_site",
    "version": "0.1.0",
    "private": true,
    "engines": {
        "node": "10.15"
    },
    "dependencies": {
        "bootstrap": "^3.4.1",
        "react": "^16.0.0",
        "react-bootstrap": "^0.31.5",
        "react-dom": "^16.0.0",
        "react-router-bootstrap": "^0.24.4",
        "react-router-dom": "^4.2.2",
        "react-scripts": "1.0.17",
        "rimraf": "^2.6.2"
    },
    "scripts": {
        "start": "rimraf ./build && react-scripts start",
        "build": "react-scripts build",
        "test": "react-scripts test --env=jsdom",
        "eject": "react-scripts eject"
    }
}

我是新来的开发人员,也是使用Azure的新人员。我使用dotnet new react -o my-new-app

创建了此应用

我尝试通过npm安装react-scripts。 还尝试添加

"engines": {
        "node": "10.15"
    },

到package.json。

2 个答案:

答案 0 :(得分:0)

这是我要解决的问题:

  • 使用最新版本更新我的所有依赖项(保留*而不是package.json中的版本)

  • 删除您的 package-lock.json

  • 尝试从管理员模型运行npm install

  • 尝试运行npm审核修复程序

  • 删除Npm和npm-cache文件夹

其他参考:请查看下面的线程:

https://github.com/facebook/create-react-app/issues/1627

看看是否可行。

答案 1 :(得分:0)

我能够将应用程序部署到Azure。

当我发布此问题时,我试图使用Kudu进行部署(持续集成)。我仍然没有找到以这种方式部署的解决方案。

现在,我在根目录中运行以下terminal / console命令:

dotnet publish -c Release -o ./publish

然后,我使用FTP客户端从/ publish部署文件。