Webpack-cli: Webpack-cli ^2.1.1 config-yargs.js looks for optionsSchema.definitions.output vs optionsSchema.definitions.outputOptions

Created on 25 Sep 2018  路  10Comments  路  Source: webpack/webpack-cli

Describe the bug

  • Config-yargs seems to be looking for optionsSchema.definitions.output instead of optionsSchema.definitions.outputOptions and my server won't start. Which path should webpack-cli be looking for? here is a gist with the contents of optionsSchema.definitions

env
node 6.9.4
npm 4.1.2

"webpack": "^4.8.3", "webpack-bundle-analyzer": "2.12.0", "webpack-cli": "^2.1.3", "webpack-dev-server": "^3.1.4", "webpack-hot-middleware": "^2.22.2", "webpack-merge": "^4.1.2",

This is causing my dev server to crash. Here is the error:

..../node_modules/webpack-cli/bin/config-yargs.js:91
  describe: optionsSchema.definitions.output.properties.path.description,
                           ^

TypeError: Cannot read property 'properties' of undefined

my config-yargs.js file:

const optionsSchema = require("webpack/schemas/WebpackOptions.json");
const CONFIG_GROUP = "Config options:";
const BASIC_GROUP = "Basic options:";
const MODULE_GROUP = "Module options:";
const OUTPUT_GROUP = "Output options:";
const ADVANCED_GROUP = "Advanced options:";
const RESOLVE_GROUP = "Resolving options:";
const OPTIMIZE_GROUP = "Optimizing options:";

console.log(JSON.stringify(optionsSchema.definitions));

module.exports = function(yargs) {
    yargs
        .help("help")
        .alias("help", "h")
        .version()
        .alias("version", "v")
        .options({
            config: {
                type: "string",
                describe: "Path to the config file",
                group: CONFIG_GROUP,
                defaultDescription: "webpack.config.js or webpackfile.js",
                requiresArg: true
            },
            "config-register": {
                type: "array",
                alias: "r",
                describe:
                    "Preload one or more modules before loading the webpack configuration",
                group: CONFIG_GROUP,
                defaultDescription: "module id or path",
                requiresArg: true
            },
            "config-name": {
                type: "string",
                describe: "Name of the config to use",
                group: CONFIG_GROUP,
                requiresArg: true
            },
            env: {
                describe: "Environment passed to the config, when it is a function",
                group: CONFIG_GROUP
            },
            mode: {
                type: optionsSchema.properties.mode.type,
                choices: optionsSchema.properties.mode.enum,
                describe: optionsSchema.properties.mode.description,
                group: CONFIG_GROUP,
                requiresArg: true
            },
            context: {
                type: optionsSchema.properties.context.type,
                describe: optionsSchema.properties.context.description,
                group: BASIC_GROUP,
                defaultDescription: "The current directory",
                requiresArg: true
            },
            entry: {
                type: "string",
                describe: optionsSchema.properties.entry.description,
                group: BASIC_GROUP,
                requiresArg: true
            },
            "module-bind": {
                type: "string",
                describe: "Bind an extension to a loader",
                group: MODULE_GROUP,
                requiresArg: true
            },
            "module-bind-post": {
                type: "string",
                describe: "Bind an extension to a post loader",
                group: MODULE_GROUP,
                requiresArg: true
            },
            "module-bind-pre": {
                type: "string",
                describe: "Bind an extension to a pre loader",
                group: MODULE_GROUP,
                requiresArg: true
            },
            output: {
                alias: "o",
                describe: "The output path and file for compilation assets",
                group: OUTPUT_GROUP,
                requiresArg: true
            },
            "output-path": {
                type: "string",
                describe: optionsSchema.definitions.output.properties.path.description,
                group: OUTPUT_GROUP,
                defaultDescription: "The current directory",
                requiresArg: true
            },
            "output-filename": {
                type: "string",
                describe:
                    optionsSchema.definitions.output.properties.filename.description,
                group: OUTPUT_GROUP,
                defaultDescription: "[name].js",
                requiresArg: true
            },
            "output-chunk-filename": {
                type: "string",
                describe:
                    optionsSchema.definitions.output.properties.chunkFilename.description,
                group: OUTPUT_GROUP,
                defaultDescription:
                    "filename with [id] instead of [name] or [id] prefixed",
                requiresArg: true
            },
            "output-source-map-filename": {
                type: "string",
                describe:
                    optionsSchema.definitions.output.properties.sourceMapFilename
                        .description,
                group: OUTPUT_GROUP,
                requiresArg: true
            },
            "output-public-path": {
                type: "string",
                describe:
                    optionsSchema.definitions.output.properties.publicPath.description,
                group: OUTPUT_GROUP,
                requiresArg: true
            },
            "output-jsonp-function": {
                type: "string",
                describe:
                    optionsSchema.definitions.output.properties.jsonpFunction.description,
                group: OUTPUT_GROUP,
                requiresArg: true
            },
            "output-pathinfo": {
                type: "boolean",
                describe:
                    optionsSchema.definitions.output.properties.pathinfo.description,
                group: OUTPUT_GROUP
            },
            "output-library": {
                type: "string",
                describe: "Expose the exports of the entry point as library",
                group: OUTPUT_GROUP,
                requiresArg: true
            },
            "output-library-target": {
                type: "string",
                describe:
                    optionsSchema.definitions.output.properties.libraryTarget.description,
                choices: optionsSchema.definitions.output.properties.libraryTarget.enum,
                group: OUTPUT_GROUP,
                requiresArg: true
            },
            "records-input-path": {
                type: "string",
                describe: optionsSchema.properties.recordsInputPath.description,
                group: ADVANCED_GROUP,
                requiresArg: true
            },
            "records-output-path": {
                type: "string",
                describe: optionsSchema.properties.recordsOutputPath.description,
                group: ADVANCED_GROUP,
                requiresArg: true
            },
            "records-path": {
                type: "string",
                describe: optionsSchema.properties.recordsPath.description,
                group: ADVANCED_GROUP,
                requiresArg: true
            },
            define: {
                type: "string",
                describe: "Define any free var in the bundle",
                group: ADVANCED_GROUP,
                requiresArg: true
            },
            target: {
                type: "string",
                describe: optionsSchema.properties.target.description,
                group: ADVANCED_GROUP,
                requiresArg: true
            },
            cache: {
                type: "boolean",
                describe: optionsSchema.properties.cache.description,
                default: null,
                group: ADVANCED_GROUP,
                defaultDescription: "It's enabled by default when watching"
            },
            watch: {
                type: "boolean",
                alias: "w",
                describe: optionsSchema.properties.watch.description,
                group: BASIC_GROUP
            },
            "watch-stdin": {
                type: "boolean",
                alias: "stdin",
                describe:
                    optionsSchema.properties.watchOptions.properties.stdin.description,
                group: ADVANCED_GROUP
            },
            "watch-aggregate-timeout": {
                describe:
                    optionsSchema.properties.watchOptions.properties.aggregateTimeout
                        .description,
                type:
                    optionsSchema.properties.watchOptions.properties.aggregateTimeout
                        .type,
                group: ADVANCED_GROUP,
                requiresArg: true
            },
            "watch-poll": {
                type: "string",
                describe:
                    optionsSchema.properties.watchOptions.properties.poll.description,
                group: ADVANCED_GROUP
            },
            hot: {
                type: "boolean",
                describe: "Enables Hot Module Replacement",
                group: ADVANCED_GROUP
            },
            debug: {
                type: "boolean",
                describe: "Switch loaders to debug mode",
                group: BASIC_GROUP
            },
            devtool: {
                type: "string",
                describe: optionsSchema.properties.devtool.description,
                group: BASIC_GROUP,
                requiresArg: true
            },
            "resolve-alias": {
                type: "string",
                describe:
                    optionsSchema.definitions.resolve.properties.alias.description,
                group: RESOLVE_GROUP,
                requiresArg: true
            },
            "resolve-extensions": {
                type: "array",
                describe:
                    optionsSchema.definitions.resolve.properties.alias.description,
                group: RESOLVE_GROUP,
                requiresArg: true
            },
            "resolve-loader-alias": {
                type: "string",
                describe: "Setup a loader alias for resolving",
                group: RESOLVE_GROUP,
                requiresArg: true
            },
            "optimize-max-chunks": {
                describe: "Try to keep the chunk count below a limit",
                group: OPTIMIZE_GROUP,
                requiresArg: true
            },
            "optimize-min-chunk-size": {
                describe:
                    optionsSchema.properties.optimization.properties.splitChunks.oneOf[1]
                        .properties.minSize.description,
                group: OPTIMIZE_GROUP,
                requiresArg: true
            },
            "optimize-minimize": {
                type: "boolean",
                describe:
                    optionsSchema.properties.optimization.properties.minimize.description,
                group: OPTIMIZE_GROUP
            },
            prefetch: {
                type: "string",
                describe: "Prefetch this request (Example: --prefetch ./file.js)",
                group: ADVANCED_GROUP,
                requiresArg: true
            },
            provide: {
                type: "string",
                describe:
                    "Provide these modules as free vars in all modules (Example: --provide jQuery=jquery)",
                group: ADVANCED_GROUP,
                requiresArg: true
            },
            "labeled-modules": {
                type: "boolean",
                describe: "Enables labeled modules",
                group: ADVANCED_GROUP
            },
            plugin: {
                type: "string",
                describe: "Load this plugin",
                group: ADVANCED_GROUP,
                requiresArg: true
            },
            bail: {
                type: optionsSchema.properties.bail.type,
                describe: optionsSchema.properties.bail.description,
                group: ADVANCED_GROUP,
                default: null
            },
            profile: {
                type: "boolean",
                describe: optionsSchema.properties.profile.description,
                group: ADVANCED_GROUP,
                default: null
            },
            d: {
                type: "boolean",
                describe:
                    "shortcut for --debug --devtool eval-cheap-module-source-map --output-pathinfo",
                group: BASIC_GROUP
            },
            p: {
                type: "boolean",
                describe:
                    "shortcut for --optimize-minimize --define process.env.NODE_ENV=\"production\"",
                group: BASIC_GROUP
            }
        });
};

Most helpful comment

migrating to latest version solved the error for me: [email protected]

All 10 comments

+1
Same error with me, using LTS for node 8.12.0.
Dependencies with version:
"webpack": "^4.11.0",
"webpack-cli": "^2.1.5",
"webpack-dev-server": "^3.1.4"

migrating to latest version solved the error for me: [email protected]

same here

we can close this issue I guess

Love to hear root cause though

Tried to fix local/global paths by attaching the webpack object to a process variable. It didn鈥檛 work, so it got reverted in webpack-cli 3+

Looks like this commit broke it

https://github.com/webpack/webpack-cli/pull/605

Yup

Webpack has chaged their definition from output to outputOptions in https://github.com/webpack/webpack/pull/7232, https://github.com/webpack/webpack/commit/3a896c96b64abb993b83f15dec460faf8d9bf2b3#diff-03af1a9344cf93838ad925ff61de02aaL328

I think the quick workround about this issue is keeping webpack version 4.19.1 earlier.

migrating to latest version solved the error for me: [email protected]

thank you. I did have the same problem. I fixed with that solution.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

logo749 picture logo749  路  4Comments

anshumanv picture anshumanv  路  3Comments

sam-s4s picture sam-s4s  路  5Comments

heyalbert picture heyalbert  路  3Comments

AjayPoshak picture AjayPoshak  路  5Comments