首页 > 解决方案 > 将 React 应用程序部署到 github 页面找不到构建文件夹

问题描述

我已经尝试部署另一个创建的应用程序create-react-app,它工作得很好。但是当我尝试部署另一个项目时,运行npm run deploy给了我这个错误:

> template-app@1.0.0 deploy D:\_studies\GitHub\React-simple-adder-multiplier-square-wall-app
> gh-pages -d build

ENOENT: no such file or directory, stat 'D:\_studies\GitHub\React-simple-adder-multiplier-square-wall-app\build'
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! template-app@1.0.0 deploy: `gh-pages -d build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the template-app@1.0.0 deploy script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\fayss\AppData\Roaming\npm-cache\_logs\2021-06-11T14_54_55_470Z-debug.log

runningnpm run build不会创建构建文件夹。这是输出:

> template-app@1.0.0 build D:\_studies\GitHub\React-simple-adder-multiplier-square-wall-app
> webpack

95% emitting emit(node:20984) [DEP_WEBPACK_COMPILATION_ASSETS] DeprecationWarning: Compilation.assets will be frozen in future, all modifications are deprecated.
BREAKING CHANGE: No more changes should happen to Compilation.assets after sealing the Compilation.
        Do changes to assets earlier, e. g. in Compilation.hooks.processAssets.
        Make sure to select an appropriate stage from Compilation.PROCESS_ASSETS_STAGE_*.
(Use `node --trace-deprecation ...` to show where the warning was created)
assets by path vendor/*.js 264 KiB
  asset vendor/react-dom.development.js 234 KiB [compared for emit] [from: vendor/react-dom.development.js] [copied] [minimized] 1 related asset    
  asset vendor/react.development.js 29.7 KiB [compared for emit] [from: vendor/react.development.js] [copied] [minimized] 1 related asset
assets by path style/ 500 bytes
  asset style/style.css 364 bytes [compared for emit] [from: src/style/style.css] [copied]
  asset style/desktop.ini 136 bytes [compared for emit] [from: src/style/desktop.ini] [copied]
asset scripts/bundle.js 2.5 MiB [compared for emit] [minimized] (name: main) 1 related asset
asset ./index.html 572 bytes [compared for emit]
runtime modules 937 bytes 4 modules
modules by path ./node_modules/ 951 KiB
  modules by path ./node_modules/@babel/runtime/helpers/esm/*.js 4.82 KiB 16 modules
  modules by path ./node_modules/scheduler/ 26.3 KiB 4 modules
  modules by path ./node_modules/prop-types/ 25.8 KiB 4 modules
  modules by path ./node_modules/react-dom/ 875 KiB 2 modules
  modules by path ./node_modules/css-loader/dist/runtime/*.js 3.78 KiB 2 modules
  modules by path ./node_modules/react-is/ 7.01 KiB 2 modules
  2 modules
modules by path ./src/ 18.3 KiB
  modules by path ./src/components/*.jsx 13.6 KiB 6 modules
  modules by path ./src/assets/style/*.css 4.29 KiB 6 modules
  ./src/scripts/main.js 399 bytes [built] [code generated]
external "React" 42 bytes [built] [code generated]
webpack 5.36.2 compiled successfully in 4064 ms

这是我package.json文件中的内容:

{
  "homepage": "http://fayssalElAnsari.github.io/React-simple-adder-multiplier-square-wall-app",
  "name": "template-app",
  "description": "template structure for js app",
  "author": "your name",
  "version": "1.0.0",
  "main": "main.js",
  "scripts": {
    "predeploy": "npm run build",
    "deploy": "gh-pages -d build",
    "build": "webpack",
    "watch": "webpack --watch",
    "dev-server": "webpack serve"
  },
  "license": "ISC",
  "devDependencies": {
    "@babel/core": "^7.12.10",
    "@babel/plugin-proposal-class-properties": "^7.12.1",
    "@babel/plugin-transform-runtime": "^7.13.10",
    "@babel/preset-env": "^7.12.10",
    "@babel/preset-react": "^7.12.13",
    "babel-loader": "^8.2.2",
    "copy-webpack-plugin": "^7.0.0",
    "css-loader": "^5.0.1",
    "file-loader": "^6.2.0",
    "gh-pages": "^3.2.0",
    "html-webpack-plugin": "^4.5.0",
    "style-loader": "^2.0.0",
    "webpack": "^5.10.1",
    "webpack-cli": "^4.2.0",
    "webpack-dev-server": "^4.0.0-beta.0"
  },
  "dependencies": {
    "prop-types": "^15.7.2",
    "react": "^17.0.1",
    "react-dom": "^17.0.1"
  }
}

我认为这是因为 webpack 而发生的,但我不确定。

标签: reactjswebpackgithub-pages

解决方案


推荐阅读