首页 > 解决方案 > Webpack - 节点模块'TypeError:...替换不是函数'

问题描述

我试过查看这样的相关答案但它们都非常不同,所以希望有人可以指导我。我对 webpack 很陌生,刚刚将我的烧瓶应用程序更新为新的引导程序主题。我突然在 docker build 中收到错误命令yard run。有趣的是以前的 git commit 构建得很好,当我恢复它时,它现在也得到了同样的错误。

TypeError: previousExtractedCommentsSource.replace is not a function
at Object.callback (/app/assets/node_modules/terser-webpack-plugin/dist/index.js:320:43)
at enqueue (/app/assets/node_modules/terser-webpack-plugin/dist/index.js:450:14)

这个答案表明它可能是代码错字,但如果是这样,我将如何找到它?

我的 webpack.config.js,如果有帮助的话:

var { merge } = require('webpack-merge');
var webpack = require('webpack');
var CopyWebpackPlugin = require('copy-webpack-plugin');
var MiniCssExtractPlugin = require('mini-css-extract-plugin');
var OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
var TerserPlugin = require('terser-webpack-plugin');

var common = {
  watchOptions: {
    poll: (process.env.WEBPACK_WATCHER_POLL || 'true') === 'true'
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: [/node_modules/],
        loader: 'babel-loader'
      },
      {
        test: [/\.scss$/, /\.css$/],
        use: [
          MiniCssExtractPlugin.loader,
          'css-loader',
          'postcss-loader',
          'sass-loader'
        ]
      },
      {
        test: /\.(png|jpg|gif|svg)$/,
        exclude: /fonts/,
        loader: 'file-loader?name=/images/[name].[ext]'
      },
      {
        test: /\.(ttf|eot|svg|woff2?)$/,
        exclude: /images/,
        use: [{
          loader: 'file-loader',
          options: {
            name: '[name].[ext]',
            outputPath: 'fonts/',
            publicPath: '../fonts'
          }
        }]
      }
    ]
  },
  optimization: {
    minimizer: [
      new TerserPlugin({cache: true, parallel: true, sourceMap: false}),
      new OptimizeCSSAssetsPlugin({})
    ]
  }
};

module.exports = [
  merge(common, {
    entry: [
      __dirname + '/app/app.scss',
      __dirname + '/app/app.js'
    ],
    output: {
      path: __dirname + '/../public',
      filename: 'js/app.js'
    },
    resolve: {
      modules: [
        '/node_modules',
        __dirname + '/app'
      ]
    },
    plugins: [
      new CopyWebpackPlugin({patterns: [{from: __dirname + '/static'}]}),
      new MiniCssExtractPlugin({filename: 'css/app.css'}),
      new webpack.ProvidePlugin({$: 'jquery', jQuery: 'jquery'}),
    ]
  })
];

我会很感激任何帮助。谢谢

标签: javascriptnode.jswebpackbootstrap-4node-modules

解决方案


推荐阅读