繁体   English   中英

Webpack错误:TypeError:require(…).usage不是函数-node_modules / webpack / bin / webpack.js:17:3

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM