无法 运行 使用带有 npm 或 yarn 的 webpack 编写脚本 - "Couldn't find the binary"
Unable to run script using webpack with npm or yarn - "Couldn't find the binary"
描述
我正在尝试使用 webpack 构建我的第一个 React 网站。使用 gulp 它构建良好。但是,当我尝试使用 webpack 在管理员下构建时,当我 运行 我的脚本 'build' 使用命令 'yarn build' 时,我收到以下错误:
error An unexpected error occurred: "Couldn't find the binary C:\WINDOWS\system32\cmd.exe;".
配置
我的节点版本是v9.8.0
我的纱线版本是1.5.1
我的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"
}
}
我的.babelrc:
{"presets": ["env", "react"]}
我的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')
}
};
我还将 Yarn 添加到我的环境变量 Path 中。
错误日志
我的 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)
非常感谢任何帮助。谢谢。
如我所料,问题出在我的 Windows 配置上,而不是我的项目。我怀疑系统环境变量是特定问题。我通过恢复 Windows.
解决了这个问题
描述
我正在尝试使用 webpack 构建我的第一个 React 网站。使用 gulp 它构建良好。但是,当我尝试使用 webpack 在管理员下构建时,当我 运行 我的脚本 'build' 使用命令 'yarn build' 时,我收到以下错误:
error An unexpected error occurred: "Couldn't find the binary C:\WINDOWS\system32\cmd.exe;".
配置
我的节点版本是v9.8.0
我的纱线版本是1.5.1
我的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"
}
}
我的.babelrc:
{"presets": ["env", "react"]}
我的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')
}
};
我还将 Yarn 添加到我的环境变量 Path 中。
错误日志
我的 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)
非常感谢任何帮助。谢谢。
如我所料,问题出在我的 Windows 配置上,而不是我的项目。我怀疑系统环境变量是特定问题。我通过恢复 Windows.
解决了这个问题