[英]Unable to run script using webpack with npm or yarn - “Couldn't find the binary”
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;".
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中。
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.