【问题标题】:npm no such file or directory when trying to run 'npm run deploy'尝试运行“npm run deploy”时,npm 没有这样的文件或目录
【发布时间】:2021-04-29 10:31:35
【问题描述】:

我收到此错误:

no such file or directory, stat 'C:\Users\nessa\VS Code\React-Django\website\frontend\build'
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! frontend@1.0.0 deploy: `gh-pages -d build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the frontend@1.0.0 deploy script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

当尝试运行 npm run deploy 时。

这是我的 package.json 文件,位于我的.\website\frontend

{
  "name": "frontend",
  "version": "1.0.0",
  "private": true,
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "react-scripts start",
    "predeploy": "npm run build",
    "deploy": "gh-pages -d build",
    "dev": "webpack --mode development --watch",
    "build": "webpack --mode production"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@babel/core": "^7.13.13",
    "@babel/preset-env": "^7.13.12",
    "@babel/preset-react": "^7.13.13",
    "babel-loader": "^8.2.2",
    "css-loader": "^5.2.0",
    "gh-pages": "^3.1.0",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "style-loader": "^2.0.0",
    "webpack": "^5.28.0",
    "webpack-cli": "^4.6.0"
  },
  "dependencies": {
    "@babel/plugin-proposal-class-properties": "^7.13.0",
    "@material-ui/core": "^4.11.3",
    "@material-ui/icons": "^4.11.2",
    "@material-ui/lab": "^4.0.0-alpha.57",
    "react-material-ui-carousel": "^2.2.4",
    "react-router-dom": "^5.2.0",
    "react-speech": "^1.0.2"
  }
}

我一直在同一个位置运行 npm run dev ,没有任何问题。我正在尝试在 Github 上托管我的 react 应用程序。我尝试重新安装 gh-pages,以防文件未正确安装但遇到同样的问题。我应该怎么做才能解决这个问题?

编辑:我试着按照here 所说的去做,但还是没有用。如果有帮助,这是我的 webpack.config.js。

const path = require("path");
const webpack = require("webpack");

module.exports = {
  entry: './src/index.js',
  output: {
    path: path.resolve(__dirname, './static/frontend'),
    filename: '[name].js',
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader',
        },
      },
      {
        test: /\.css$/i,
        use: ['style-loader', 'css-loader'],
      },
    ],
  },
  optimization: {
    minimize: true,
  },
  plugins: [
    new webpack.DefinePlugin({
      'process.env.NODE_ENV': JSON.stringify('development'),
    }),
  ],
}

我还将 package.json 脚本中的“build”:“webpack --mode production”更改为“build”:“webpack --mode development”,以便运行 npm run build,但问题仍然存在t 固定。

【问题讨论】:

  • “build”文件夹是否存在?
  • 不行,有没有办法单独安装?
  • 运行npm run build(它将创建构建文件夹),然后运行npm run deploy。
  • 如果有帮助,我编辑了我的原始帖子,但这样做仍然没有任何作用。似乎仍然没有构建文件夹。
  • 在这种情况下,我会按照 webpack 上的一些教程来找出为什么 npm run build 不输出“build”或“dist”文件夹,或者如果可能的话,我会设置一个新的使用 CRA 的项目(它将提供所有预先配置的内容)。

标签: node.js reactjs github npm github-pages


【解决方案1】:

这是我的错误: ENOENT:没有这样的文件或目录,stat 'C:\Users...\dist'

所以我添加了 "predeploy": "npm run build", "deploy": "gh-pages -d build", 在 "scripts" 中的 package.json 上。

并在终端中运行命令npm install gh-pages --save-dev。

以npm run deploy 结束。

【讨论】:

    猜你喜欢
    • 2020-09-28
    • 2016-02-19
    • 2018-05-15
    • 1970-01-01
    • 2018-09-29
    • 2020-03-08
    • 1970-01-01
    • 1970-01-01
    • 2018-02-15
    相关资源
    最近更新 更多