首页 > 解决方案 > 将 non-create-react-app React 项目部署到 Github Pages 时出现问题

问题描述

我构建了一个相当简单的反应应用程序(但不是使用创建反应应用程序,而是使用自定义 webpack-react 设置)并且一直在努力将它放到 Github 页面上。我遵循了各种(许多)准则,例如在 package.json 中添加主页和部署脚本以及安装 gh-pages 依赖项。尝试过部署

"gh-pages -d build" or "gh-pages -b master -d build" 

我认为它必须与 webpack 设置有关,但我不确定如何解决这个问题。如果不可能,我愿意使用其他网页托管服务。

"homepage": "http://davt49.github.io/calculatorapp",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"serve": "webpack-dev-server --mode=development",
"build": "webpack -p",
"predeploy": "npm run build",
"deploy": "gh-pages -d build"
},

尝试 npm run deploy 时出现“ENOENT:没有这样的文件或目录”错误:

> basic-react-webpack-setup@1.0.0 predeploy /Users/davidtsui/development/classwork/calculator-app-main
> npm run build


> basic-react-webpack-setup@1.0.0 build /Users/davidtsui/development/classwork/calculator-app-main
> webpack -p

Hash: 187514d9cee9f778efcf Version: webpack 4.46.0 Time: 1308ms Built at: 09/23/2021 2:58:54 PM
               Asset       Size  Chunks             Chunk Names assets/calculator.js   2.48 KiB          [emitted]  
           bundle.js    157 KiB       0  [emitted]  main
          index.html  388 bytes          [emitted]   Entrypoint main = bundle.js  [1] ./node_modules/css-loader/dist/cjs.js!./node_modules/sass-loader/dist/cjs.js!./src/style.scss
8.58 KiB {0} [built]  [4] ./src/assets/calculator.js 6.43 KiB {0} [built]  [5] ./src/app.js 5.54 KiB {0} [built] [10] ./src/style.scss
1.18 KiB {0} [built]
    + 10 hidden modules Child html-webpack-plugin for "index.html":
     1 asset
    Entrypoint undefined = index.html
    [0] ./node_modules/html-webpack-plugin/lib/loader.js!./src/index.html 540 bytes {0} [built]
    [2] (webpack)/buildin/global.js 472 bytes {0} [built]
    [3] (webpack)/buildin/module.js 497 bytes {0} [built]
        + 1 hidden module

> basic-react-webpack-setup@1.0.0 deploy /Users/davidtsui/development/classwork/calculator-app-main
> gh-pages -d build

ENOENT: no such file or directory, stat '/Users/davidtsui/development/classwork/calculator-app-main/build' 
npm ERR! code ELIFECYCLE 
npm ERR! errno 1 
npm ERR! basic-react-webpack-setup@1.0.0 deploy: `gh-pages -d build` 
npm ERR! Exit status 1 
npm ERR!  
npm ERR! Failed at the basic-react-webpack-setup@1.0.0 deploy script. 
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

感谢任何帮助,以及我可以调查的地方。如果需要,我可以共享 webpack 配置文件。

标签: reactjswebpackerror-handlingweb-deploymentgithub-pages

解决方案


推荐阅读