繁体   English   中英

Webpack - 节点模块“类型错误:...替换不是函数”

[英]Webpack - node module 'TypeError: ...replace is not a function'

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

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'}),
    ]
  })
];

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

在我的情况下,添加type: "asset/resource",之后

        test: /\.(png|jpg|gif|svg)$/,
        exclude: /fonts/,
        loader: 'file-loader?name=/images/[name].[ext]'

解决了这个问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM