![](/img/trans.png)
[英]Cant run npm script, it shown “Error: spawn node_modules/webpack/bin/webpack.js EACCES”
[英]Webpack Error: TypeError: require(…).usage is not a function - node_modules/webpack/bin/webpack.js:17:3
這是我的設置:
NodeJS:7.6.0
NPM:4.4.1
的package.json
{
"name": "Fieldstart",
"version": "1.0.0",
"description": "Fieldstart",
"main": "webpack.config.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"babel": "babel",
"webpack": "webpack"
},
"author": "Conrad Brinker",
"license": "ISC",
"dependencies": {
"axios": "^0.15.3",
"babel": "^6.23.0",
"babel-cli": "^6.24.0",
"babel-core": "6.24.0",
"babel-loader": "^6.4.0",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-plugin-react-html-attrs": "^2.0.0",
"babel-plugin-transform-class-properties": "^6.23.0",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-preset-es2015": "^6.24.0",
"babel-preset-react": "^6.23.0",
"babel-preset-stage-0": "^6.22.0",
"gulp": "3.9.1",
"gulp-concat": "2.6.1",
"gulp-rename": "1.2.2",
"gulp-sass": "3.1.0",
"gulp-uglify": "2.0.1",
"node-sass": "4.5.0",
"react": "15.4.2",
"react-dom": "15.4.2",
"react-redux": "^5.0.3",
"react-router": "^4.0.0",
"react-router-redux": "^4.0.8",
"redux": "^3.6.0",
"redux-thunk": "^2.2.0",
"remote-redux-devtools": "^0.5.7",
"webpack": "^2.2.1"
}
}
webpack.config.js
const debug = process.env.NODE_ENV !== "production";
const webpack = require('webpack');
const path = require('path');
module.exports = {
context: path.join(__dirname, "jsx"),
devtool: debug ? "inline-sourcemap" : null,
watch: true,
//devtool: 'source-map',
entry: "./jsx/main.js",
output: {
path: path.resolve(__dirname + "/../html/app"),
filename: "fs.js",
publicPath: "/js/"
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: "babel-loader",
options: {
presets: ['react', 'es2015', 'stage-0'],
plugins: ['react-html-attrs', 'transform-decorators-legacy', 'transform-class-properties']
}
}
]
},
resolve: {
extensions: ['.js']
},
plugins: debug ? [] : [
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin({
compress: { screw_ie8: true, warnings: false },
mangle: false,
sourcemap: false,
comments: false
})
]
};
當我去運行“ npm run webpack”時,我得到這個輸出
> Fieldstart@1.0.0 webpack /var/www/src
> webpack
/var/www/src/node_modules/webpack/bin/webpack.js:17
.usage("webpack " + require("../package.json").version + "\n" +
^
TypeError: require(...).usage is not a function
at Object.<anonymous> (/var/www/src/node_modules/webpack/bin/webpack.js:17:3)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:422:7)
at startup (bootstrap_node.js:143:9)
at bootstrap_node.js:537:3
看來我的配置和webpack有問題嗎? 我一直在嘗試尋找答案並以不同的方式更改我的配置,但是沒有運氣。
您的配置不是問題。 但是似乎webpack的依賴項之一存在問題,即yargs
。 npm可能存在問題,使其安裝了損壞的版本。 您應該刪除node_modules
並重新安裝依賴項,並確保不使用與緩存中相同的broekn軟件包,您也可以清除npm緩存。
rm -rf node_modules
npm cache clear
npm install
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.