简体   繁体   English

无法将Webpack与npm或yarn一起使用脚本-“找不到二进制文件”

[英]Unable to run script using webpack with npm or yarn - “Couldn't find the binary”

Description 描述

I'm trying to build my first React website using webpack. 我正在尝试使用webpack构建我的第一个React网站。 With gulp it builds fine. 用大口吃它可以很好地构建。 However when trying to build under administrator using webpack, when I run my script 'build' using the command 'yarn build', I get the following error: 但是,当尝试使用webpack在管理员下进行构建时,当我使用命令“ yarn build”运行脚本“ build”时,出现以下错误:

error An unexpected error occurred: "Couldn't find the binary C:\\WINDOWS\\system32\\cmd.exe;".

Configuration 组态

My node version is v9.8.0 我的节点版本是v9.8.0

My yarn version is 1.5.1 我的纱线版本是1.5.1

My package.json: 我的package.json:

 {
  "name": "mywebsite",
  "version": "1.0.0",
  "description": "My personal website.",
  "main": "./src/App.jsx",
  "scripts": {
    "build": "webpack-dev-server --config ./webpack.config.js --mode development"
  },
  "author": "Akli Aissat",
  "license": "ISC",
  "dependencies": {
    "react": "^16.2.0",
    "react-dom": "^16.2.0",
    "react-router-dom": "^4.2.2"
  },
  "devDependencies": {
    "babel-core": "^6.26.0",
    "babel-loader": "^7.1.4",
    "babel-preset-env": "^1.6.1",
    "babel-preset-react": "^6.24.1",
    "webpack": "^4.1.1",
    "webpack-cli": "^2.0.12",
    "webpack-dev-server": "^3.1.1"
  }
}

My .babelrc: 我的.babelrc:

{"presets": ["env", "react"]}

My webpack.config.js: 我的webpack.config.js:

const path = require("path");

module.exports = {
  entry: "./src/App",
  output: {
    path: path.resolve(__dirname, "dist"),
    filename: "bundle.js"
  },
  module: {
    rules: [
      {
        test: /\.(js|jsx)$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader"
        }
      }
    ]
  },
  devServer: {
    contentBase: path.join(__dirname, 'dist')
  }
};

I've also added Yarn to my environment variable Path. 我还已经将Yarn添加到环境变量Path中。

Error Logs 错误记录

My yarn-error.log doesn't really give me any additional information about the error: 我的yarn-error.log并未真正提供有关该错误的任何其他信息:

Trace: 
  Error: Couldn't find the binary C:\WINDOWS\system32\cmd.exe;
      at ProcessSpawnError.MessageError (C:\Program Files (x86)\Yarn\lib\cli.js:186:110)
      at new ProcessSpawnError (C:\Program Files (x86)\Yarn\lib\cli.js:201:118)
      at ChildProcess.<anonymous> (C:\Program Files (x86)\Yarn\lib\cli.js:30237:18)
      at ChildProcess.emit (events.js:180:13)
      at Process.ChildProcess._handle.onexit (internal/child_process.js:207:12)
      at onErrorNT (internal/child_process.js:379:16)
      at process._tickCallback (internal/process/next_tick.js:114:19)

Any help would be very much appreciated. 任何帮助将不胜感激。 Thanks. 谢谢。

As I suspected, the problem was with my Windows configuration and not my project. 正如我所怀疑的那样,问题出在我的Windows配置而不是我的项目。 I suspect the system environment variables was the specific issue. 我怀疑系统环境变量是特定问题。 I resolved this by restoring Windows. 我通过还原Windows解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 流星NPM:无法运行`npm收缩包装` - Meteor NPM : Couldn't run `npm shrinkwrap` 当yarn是运行命令时,使用npm的circleci(v2.0) - circleci (v2.0) using npm when yarn is the run command 无法让 npm 运行启动 testcafe 的脚本 - Unable to have npm run a script that starts testcafe 在“ npm”注册表中找不到软件包“ babel-present-react” - Couldn't find package “babel-present-react” on the “npm” registry 创建 package 时无法在“npm”注册表中找到 package“反应” - Couldn't find package "react" on the "npm" registry when creating a package Next JS 无法执行 npm 运行构建(webpack 错误)? - Next JS unable to execute npm run build (webpack error)? 使用 yarn + webpack 从 fork 安装 npm 包 - 无法解析 &#39;./dist/ - Installing npm package from fork with yarn + webpack - Can't resolve './dist/ 无法运行“纱线运行构建” - unable to run 'yarn run build' 如何在具有纱线的vsts中创建react build管道。 找不到package.json - How to create a react build pipeline in vsts with yarn. Couldn't find a package.json 纱线安装 - 找不到与 [最新版本] 匹配的任何版本“react-is” - Yarn install - Couldn't find any version "react-is" that matches [Latest version]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM