鍍金池/ 問答/HTML/ vue項(xiàng)目使用webpack打包時(shí)報(bào)錯(cuò),如何解決?

vue項(xiàng)目使用webpack打包時(shí)報(bào)錯(cuò),如何解決?

問題

昨天在寫代碼的時(shí)候,電腦的硬盤突然不知道咋的讀不出來了,然后等搞好之后發(fā)現(xiàn)項(xiàng)目的dev環(huán)境是好的,但是在build的時(shí)候發(fā)現(xiàn)報(bào)錯(cuò)了,報(bào)錯(cuò)信息顯示在webpack.prod.conf.js中,是一個(gè)webpack的插件報(bào)錯(cuò),我重新install了這個(gè)插件之后,又出現(xiàn)了另一個(gè)報(bào)錯(cuò),報(bào)錯(cuò)信息如下:

> vue-notes-app@1.0.0 build D:\workspace\platform_new\kb-frontend-ui
> node build/build.js

D:\workspace\platform_new\kb-frontend-ui\node_modules\postcss-merge-rules\node_modules\caniuse-api\dist\index.js:36
var parse = (0, _lodash2.default)(_utils.parseCaniuseData, function (feature, browsers)
{
                                 ^

TypeError: (0 , _lodash2.default) is not a function
    at Object.<anonymous> (D:\workspace\platform_new\kb-frontend-ui\node_modules\postcss-merge-rules\node_modules\caniuse-api\dist\index.js:36:34)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (D:\workspace\platform_new\kb-frontend-ui\node_modules\postcss-merge-rules\dist\lib\ensureCompatibility.js:7:19)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)

npm ERR! Windows_NT 10.0.14393
npm ERR! argv "C:\\Program Files (x86)\\nodejs\\node.exe" "C:\\Program Files (x86)\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "build"
npm ERR! node v6.9.4
npm ERR! npm  v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! vue-notes-app@1.0.0 build: `node build/build.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the vue-notes-app@1.0.0 build script 'node build/build.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the vue-notes-app package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node build/build.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs vue-notes-app
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls vue-notes-app
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     D:\workspace\platform_new\kb-frontend-ui\npm-debug.log

找了一圈資料不知道該怎么解決問題,所以來請(qǐng)教。

貼上一部分webpack.prod.conf.js的配置

'use strict'
const path = require('path')
const utils = require('./utils')
const webpack = require('webpack')
const config = require('../config')
const merge = require('webpack-merge')
const baseWebpackConfig = require('./webpack.base.conf')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin')

const env = process.env.NODE_ENV === 'testing'
  ? require('../config/test.env')
  : config.build.env

const webpackConfig = merge(baseWebpackConfig, {
  module: {
    rules: utils.styleLoaders({
      sourceMap: config.build.productionSourceMap,
      extract: true
    })
  },
  devtool: config.build.productionSourceMap ? '#source-map' : false,
  output: {
    path: config.build.assetsRoot,
    filename: utils.assetsPath('js/[name].[chunkhash].js'),
    chunkFilename: utils.assetsPath('js/[id].[chunkhash].js')
  },
  plugins: [
    // http://vuejs.github.io/vue-loader/en/workflow/production.html
    new webpack.DefinePlugin({
      'process.env': env
    }),
    // UglifyJs do not support ES6+, you can also use babel-minify for better treeshaking: https://github.com/babel/minify
    new webpack.optimize.UglifyJsPlugin({
      compress: {
        warnings: false
      },
      sourceMap: true
    }),
    // extract css into its own file
    new ExtractTextPlugin({
      filename: utils.assetsPath('css/[name].[contenthash].css')
    }),
    // Compress extracted CSS. We are using this plugin so that possible
    // duplicated CSS from different components can be deduped.
    new OptimizeCSSPlugin({
      cssProcessorOptions: {
        safe: true
      }
    }),
    // generate dist index.html with correct asset hash for caching.
    // you can customize output by editing /index.html
    // see https://github.com/ampedandwired/html-webpack-plugin
    new HtmlWebpackPlugin({
      filename: process.env.NODE_ENV === 'testing'
        ? 'index.html'
        : config.build.index,
      template: 'index.html',
      inject: true,
      minify: {
        removeComments: true,
        collapseWhitespace: true,
        removeAttributeQuotes: true
        // more options:
        // https://github.com/kangax/html-minifier#options-quick-reference
      },
      // necessary to consistently work with multiple chunks via CommonsChunkPlugin
      chunksSortMode: 'dependency'
    }),
    // keep module.id stable when vender modules does not change
    new webpack.HashedModuleIdsPlugin(),
    // split vendor js into its own file
    new webpack.optimize.CommonsChunkPlugin({
      name: 'vendor',
      minChunks: function (module) {
        // any required modules inside node_modules are extracted to vendor
        return (
          module.resource &&
          /\.js$/.test(module.resource) &&
          module.resource.indexOf(
            path.join(__dirname, '../node_modules')
          ) === 0
        )
      }
    }),
    // extract webpack runtime and module manifest to its own file in order to
    // prevent vendor hash from being updated whenever app bundle is updated
    new webpack.optimize.CommonsChunkPlugin({
      name: 'manifest',
      chunks: ['vendor']
    }),
    // copy custom static assets
    new CopyWebpackPlugin([
      {
        from: path.resolve(__dirname, '../static'),
        to: config.build.assetsSubDirectory,
        ignore: ['.*']
      }
    ])
  ]
})

if (config.build.productionGzip) {
  const CompressionWebpackPlugin = require('compression-webpack-plugin')

  webpackConfig.plugins.push(
    new CompressionWebpackPlugin({
      asset: '[path].gz[query]',
      algorithm: 'gzip',
      test: new RegExp(
        '\\.(' +
        config.build.productionGzipExtensions.join('|') +
        ')$'
      ),
      threshold: 10240,
      minRatio: 0.8
    })
  )
}

if (config.build.bundleAnalyzerReport) {
  const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
  webpackConfig.plugins.push(new BundleAnalyzerPlugin())
}

module.exports = webpackConfig

好著急,PM快要把我按在地上催了

回答
編輯回答
兔囡囡

建議直接去postcss-merge-rules或者caniuse-api的github搜索相關(guān)issues

2018年1月17日 04:56
編輯回答
憶往昔

把你lodash引用的地方的代碼貼出來。

2018年1月13日 20:19
編輯回答
陪妳哭
D:\workspace\platform_new\kb-frontend-ui\node_modules\postcss-merge-rules\node_modules\caniuse-api\dist\index.js:36
var parse = (0, _lodash2.default)(_utils.parseCaniuseData, function (feature, browsers)
{
                                ^
TypeError: (0 , _lodash2.default) is not a function

這不是報(bào)lodash工具庫的錯(cuò)誤嗎?

2017年4月21日 21:43