最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】npm run build出错:validateOptions.js throw new _ValidationError2.default(ajv.errors, name)

npm crifan 5978浏览 0评论

折腾:

【临时解决】webpack打包失败:ERROR in bundle js from UglifyJs Unexpected token punc

期间,去试试把

new webpack.optimize.UglifyJsPlugin({

换成

uglifyjs-webpack-plugin的UglifyJSPlugin

import UglifyJSPlugin from ‘uglifyjs-webpack-plugin’;
// new webpack.optimize.UglifyJsPlugin({
new UglifyJSPlugin({
})

结果运行出错:

➜  ucowsapp_h5_en git:(master) ✗ npm run build
> [email protected] prebuild /Users/crifan/dev/dev_root/xxx/ucowsapp_h5_en
> npm run clean && mkdirp build && ncp src/assets build/assets
> [email protected] clean /Users/crifan/dev/dev_root/xxx/ucowsapp_h5_en
> rm -rf build/ build.zip
> [email protected] build /Users/crifan/dev/dev_root/xxx/ucowsapp_h5_en
> cross-env NODE_ENV=production webpack –verbose -p –progress
/Users/crifan/dev/dev_rootxxx/ucowsapp_h5_en/node_modules/schema-utils/dist/validateOptions.js:40
    throw new _ValidationError2.default(ajv.errors, name);
    ^
false
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build: `cross-env NODE_ENV=production webpack –verbose -p –progress`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] 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!     /Users/crifan/.npm/_logs/2017-10-24T09_08_04_688Z-debug.log

validateOptions.js throw new _ValidationError2.default(ajv.errors, name)

此处的完整配置是:

    // new webpack.optimize.UglifyJsPlugin({
    new UglifyJSPlugin({
      output: {
        comments: false
      },
      compress: {
        unsafe_comps: true,
        properties: true,
        keep_fargs: false,
        pure_getters: true,
        collapse_vars: true,
        unsafe: true,
        warnings: false,
        screw_ie8: true,
        sequences: true,
        dead_code: true,
        drop_debugger: true,
        comparisons: true,
        conditionals: true,
        evaluate: true,
        booleans: true,
        loops: true,
        unused: true,
        hoist_funs: true,
        if_return: true,
        join_vars: true,
        cascade: true,
        drop_console: true
      }
    }),

估计是参数不支持?

所以去找uglifyjs-webpack-plugin官网看看参数

webpack-contrib/uglifyjs-webpack-plugin: UglifyJS plugin for webpack

好像是把上述参数放到:uglifyOptions估计就可以了。

    // new webpack.optimize.UglifyJsPlugin({
    new UglifyJSPlugin({
      uglifyOptions: {
        output: {
          comments: false
        },
        compress: {
          unsafe_comps: true,
          properties: true,
          keep_fargs: false,
          pure_getters: true,
          collapse_vars: true,
          unsafe: true,
          warnings: false,
          screw_ie8: true,
          sequences: true,
          dead_code: true,
          drop_debugger: true,
          comparisons: true,
          conditionals: true,
          evaluate: true,
          booleans: true,
          loops: true,
          unused: true,
          hoist_funs: true,
          if_return: true,
          join_vars: true,
          cascade: true,
          drop_console: true
        }
      }
    }),

结果

就可以了。

【总结】

此处

validateOptions.js throw new _ValidationError2.default(ajv.errors, name)

的原因是:

webpack.optimize.UglifyJsPlugin

换成

UglifyJSPlugin

对应的之前uglify的参数,不是直接支持的。

解决办法:把之前参数放到uglifyOptions就可以了。

转载请注明:在路上 » 【已解决】npm run build出错:validateOptions.js throw new _ValidationError2.default(ajv.errors, name)

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
90 queries in 0.164 seconds, using 22.10MB memory