question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: url.replace is not a function

See original GitHub issue
  • Node Version: 16.4.2
  • Yarn Version: 1.22.10
  • webpack Version: 5.45.1
  • mini-css-extract-plugin Version: 2.1.0
  • css-loader Verion: 6.2.0
  • @fortawesome/fontawesome-free" Version: 5.15.3
  • css-minimizer-webpack-plugin: 3.0.2

Expected Behavior

Can Compiled successfully

Actual Behavior

Failed to compile

Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):
TypeError: url.replace is not a function

Code

loader

const path = require('path');
const webpack = require('webpack');
const { VueLoaderPlugin } = require('vue-loader');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');

module.exports = {
  module: {
    rules: [
      {
        test: /\.s[ac]ss$/i,
        use: [
          MiniCssExtractPlugin.loader,
          "css-loader",
          "postcss-loader",
          "sass-loader"
        ],
      },
      {
        test: /\.vue(\.erb)?$/,
        use: { loader: 'vue-loader' },
        options: {     
          postcss: [require('postcss-cssnext')()]
        }
      },
      {
        test: /\.(eot|svg|ttf|woff|woff2)(\?\S*)?$/,
        loader: 'file-loader',
        use: [
          {
            loader: 'file-loader',
            options: {
              name: 'font/[name].[ext]',
            },
          },
        ],
      },
    ]
  },
  plugins: [
    new webpack
      .ContextReplacementPlugin(/\.\/locale$/, 'empty-module', false, /js$/),
    new VueLoaderPlugin(),
    new MiniCssExtractPlugin()
  ],
  resolve: {
    modules: [
      path.resolve('./app/javascript/'),
    ],
    alias: {
      '~components': path.resolve('./app/javascript/components'),
      '~commons': path.resolve('./app/javascript/commons'),
      '~configuration': path.resolve('./app/javascript/packs/configuration'),
      '~mixins': path.resolve('./app/javascript/mixins'),
      '~mutations': path.resolve('./app/javascript/mutations'),
      '~queries': path.resolve('./app/javascript/queries'),
      '~pages': path.resolve('./app/javascript/pages'),
      '~store': path.resolve('./app/javascript/store')
    },
    extensions: ['*', '.js', '.vue', '.json', '.css', '.sass', '.scss'],
  },
};

application.scss

$fa-font-path: '~@fortawesome/fontawesome-free/webfonts';
@import '~@fortawesome/fontawesome-free/scss/fontawesome'; <--- error in here

How Do We Reproduce?

Please Add css-loader and @fortawesome/fontawesome-free and mini-css-extract-plugin and version on Top then compile.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:17 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
alexander-akaitcommented, Jul 21, 2021

Thanks I will look at this in near future

1reaction
alexander-akaitcommented, Aug 2, 2021

Bug in webpacker, go to node_modules/@rails/webpacker/package/rules/svg.js and change content on:

/* eslint global-require: 0 */
/* eslint import/no-dynamic-require: 0 */

module.exports = {
  test: /\.svg$/i,
  type: 'asset/inline',
  generator: {
    dataUrl: (content) => {
      let optimisedContent = content

      try {
        if (require.resolve('mini-svg-data-uri')) {
          const svgToMiniDataURI = require('mini-svg-data-uri')
          optimisedContent = svgToMiniDataURI(content.toString())
        }
      } catch (e) {
        /* Work out what to print here */
      }

      return optimisedContent.toString()
    }
  }
}

dataUrl should return string, not Buffer https://github.com/webpack/webpack/blob/main/types.d.ts#L278, sorry we can’t fix it here

Also if you faced with this issue most likely a problem:

  • you use file-loader or url-loader and forgot to add type: 'javascript/auto' https://webpack.js.org/guides/asset-modules/ (no top), we strongly recommend migrate to asset modules
  • you apply loader some loaders twice (check you test/include/exclude)
  • you use custom function for generate data URI and it is buggy
  • you use wrong loader for svg, for example @svgr/webpack generate named export, not URL, so if you use this loader for all svg files you will have problems with HTML/CSS/other not js/jsx

Feel free to feedback

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: TypeError: url.replace is not a function #731 - GitHub
Error: TypeError: url.replace is not a function #731 ... module.exports = function escape(url) { // If url is already wrapped in quotes, ...
Read more >
TypeError: replace is not a function in JavaScript | bobbyhadz
The "replace is not a function" error occurs when we call the replace() method on a value that is not of type string...
Read more >
AngularJS JSONP TypeError: url.replace is not a function
I am trying to get URL using zillow api in angular JS. angular.module('account.settings').controller('AccountSettingsCtrl', ...
Read more >
Fixed - Uncaught TypeError: a.replace is not a function
This does assume that newCount is a string, but this might not necessarily be the case - on initial page load this is...
Read more >
TypeError: t.replace is not a function - WordPress.org
We are getting a console error which seems to be related to (not sure if it's ... TypeError: t.replace is not a function...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found