【问题标题】:No "build" folder found when running npm run deploy运行 npm run deploy 时找不到“build”文件夹
【发布时间】:2018-01-22 23:47:14
【问题描述】:

我正在尝试将我的 react 应用程序部署到 github 页面。每次我运行“npm run deploy”时都会收到此错误:

ENOENT: no such file or directory, stat '/Users/username/my-app/build'

npm ERR! Darwin 16.3.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "deploy"
npm ERR! node v6.11.0
npm ERR! npm  v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! reactdemo@1.0.0 deploy: `gh-pages -d build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the reactdemo@1.0.0 deploy script 'gh-pages -d build'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the reactdemo package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     gh-pages -d build
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs reactdemo
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls reactdemo
npm ERR! There is likely additional logging output above.

这是我的 package.json 脚本

"scripts": {
    "compile": "webpack",
    "test": "echo \"Error: no test specified\" && exit 1",
    "build": "webpack --config webpack.config.js",
    "predeploy": "npm run build",
    "deploy": "gh-pages -d build"
  },

Webpack.config.js

const path = require('path');

module.exports = {
  context: path.join(__dirname, 'src'),
  entry: [
    './main.js',
  ],
  output: {
    path: path.join(__dirname, 'www'),
    filename: 'bundle.js',
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: [
          'babel-loader',
        ],
      },
    ],
  },
  resolve: {
    modules: [
      path.join(__dirname, 'node_modules'),
    ],
  },
};

我猜这与我的构建脚本的编写方式有关。运行“npm run build”工作正常。

编辑:添加 webpack 配置

【问题讨论】:

  • 你能分享一下你的 webpack.config.js 的内容吗?
  • @Shubham Jain 我将 webpack 文件添加到我的帖子中
  • 在你的项目中创建一个构建文件夹,看看命令是否有效?

标签: reactjs github npm


【解决方案1】:

命令gh-pages -d build 将从您的build 目录部署所有内容。但是你不使用build 目录作为你的包,你使用www 目录。

将命令改为gh-pages -d www

【讨论】:

    猜你喜欢
    • 2019-11-15
    • 1970-01-01
    • 1970-01-01
    • 2021-03-03
    • 2020-05-10
    • 2021-09-13
    • 2021-02-18
    • 2020-09-14
    • 1970-01-01
    相关资源
    最近更新 更多