又遇到一个很神奇的问题,在使用 webpack 编译的时候,出现如下错误:

king@king:/data/www/mkd$ npm run build

> markdown-report-mail@1.0.0 build /data/www/mkd
> cross-env NODE_ENV=production webpack

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

TypeError: Cannot read property 'properties' of undefined
    at module.exports (/data/www/mkd/node_modules/webpack-cli/bin/config-yargs.js:89:48)
    at /data/www/mkd/node_modules/webpack-cli/bin/webpack.js:60:27
    at Object.<anonymous> (/data/www/mkd/node_modules/webpack-cli/bin/webpack.js:515:3)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:20:18)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! markdown-report-mail@1.0.0 build: `cross-env NODE_ENV=production webpack`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the markdown-report-mail@1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/king/.npm/_logs/npm-debug.log

我 scripts 配置是没问题的:

  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build": "cross-env NODE_ENV=production webpack",
  }

神奇的地方是直接执行 webpack 是没问题,可以编译出来的,直接使用 cross-env 命令 cross-env NODE_ENV=production webpack 也是没有问题啊,为何写到 scripts 里就不行了呢,我搜索了一下这个问题发现他们说是因为 webpack-cli 版本的问题,升级到3.1.1版本或更新即可…

npm i webpack-cli@3.1.1 -D

emmmmm,似乎真的可以了…