Gary Sieling

Fixing webpack error: TypeError: request.replace is not a function

If you try to set up multiple entry points in Webpack, you can get the following error:

D:\projects\image-annotation\node_modules\webpack\lib\NormalModuleFactory.js:72
                        var elements = request.replace(/^-?!+/, "").replace(/!!+/g, "!").split("!");
                                               ^

TypeError: request.replace is not a function
    at D:\projects\image-annotation\node_modules\webpack\lib\NormalModuleFactory.js:72:27
    at D:\projects\image-annotation\node_modules\webpack\lib\NormalModuleFactory.js:28:4
    at D:\projects\image-annotation\node_modules\webpack\lib\NormalModuleFactory.js:159:3
    at NormalModuleFactory.applyPluginsAsyncWaterfall (D:\projects\image-annotation\node_modules\webpack\node_modules\tapable\lib\Tapable.js:75:69)
    at NormalModuleFactory.create (D:\projects\image-annotation\node_modules\webpack\lib\NormalModuleFactory.js:144:8)
    at D:\projects\image-annotation\node_modules\webpack\lib\Compilation.js:214:11
    at D:\projects\image-annotation\node_modules\webpack\node_modules\async\lib\async.js:181:20
    at Object.async.forEachOf.async.eachOf (D:\projects\image-annotation\node_modules\webpack\node_modules\async\lib\async.js:233:13)
    at Object.async.forEach.async.each (D:\projects\image-annotation\node_modules\webpack\node_modules\async\lib\async.js:209:22)
    at Compilation.addModuleDependencies (D:\projects\image-annotation\node_modules\webpack\lib\Compilation.js:185:8)

Basically, the problem is that if you create a webpack config file, it doesn’t have the ability to tell you that the JSON object is the wrong shape, because it isn’t testing this like it should.

For instance, I got this error because I did this:

module.exports = {   
  entry: [
    {
      ssl_search: "./src/ssl_search/Entry.js"
    }
  ]
}

When I really should have done this:

module.exports = {   
  entry: {
    ssl_search: "./src/ssl_search/Entry.js"
  }
}
Exit mobile version