Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webpack.config.flatMap is not a function for Webpack >5.84.0

Tags:

webpack

I was following a tutorial on webpack and bumped into an error right at the beginning whilst trying to get webpack to compile.

After installing webpack and webpack-cli, I got the following error when trying to run a build script:

[webpack-cli] TypeError: ["webpack.config",".webpack/webpack.config",".webpack/webpackfile"].flatMap is not a function
    at WebpackCLI.loadConfig (C:\Users\xxxxxxxxxx\Documents\Repositories\webpack-starter\node_modules\webpack-cli\lib\webpack-cli.js:1439:15)    at WebpackCLI.createCompiler (C:\Users\xxxxxxxxxxx\Documents\Repositories\webpack-starter\node_modules\webpack-cli\lib\webpack-cli.js:1714:33)
    at WebpackCLI.runWebpack (C:\Users\xxxxxxxxxxx\Documents\Repositories\webpack-starter\node_modules\webpack-cli\lib\webpack-cli.js:1810:31)    at Command.makeCommand (C:\Users\xxxxxxxxxxx\Documents\Repositories\webpack-starter\node_modules\webpack-cli\lib\webpack-cli.js:892:32)   
    at Command.listener [as _actionHandler] (C:\Users\xxxxxxxx\Documents\Repositories\webpack-starter\node_modules\webpack-cli\node_modules\commander\lib\command.js:482:17)
    at actionResult._chainOrCall (C:\Users\xxxxxxxxxxx\Documents\Repositories\webpack-starter\node_modules\webpack-cli\node_modules\commander\lib\command.js:1283:65)
    at Command._chainOrCall (C:\Users\xxxxxxxxxxxxx\Documents\Repositories\webpack-starter\node_modules\webpack-cli\node_modules\commander\lib\command.js:1177:12)
    at Command._parseCommand (C:\Users\xxxxxxxxxxxxx\Documents\Repositories\webpack-starter\node_modules\webpack-cli\node_modules\commander\lib\command.js:1283:27)
    at hookResult._chainOrCall (C:\Users\xxxxxxxxx\Documents\Repositories\webpack-starter\node_modules\webpack-cli\node_modules\commander\lib\command.js:1081:27)
    at Command._chainOrCall (C:\Users\xxxxxxxxxxxx\Documents\Repositories\webpack-starter\node_modules\webpack-cli\node_modules\commander\lib\command.js:1177:12)
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] build: `webpack --mode production`       
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\xxxxxxxx\AppData\Roaming\npm-cache\_logs\2023-05-26T14_49_54_605Z-debug.log

When I downgraded to webpack 5.70.0 from 5.84.0 and webpack-cli from 5.0.1 to 4.9.2 the error went away.

Is it possible to get a very simple npm build working with the current versions of webpack or is it an unfixable breaking change?

like image 893
Robert Carmichael Avatar asked Nov 29 '25 17:11

Robert Carmichael


1 Answers

I actually just encountered this issue and probably from the same tutorial. I tried downgrading those dependencies as you did, but I was unsuccessful. I ended up installing the latest version of node, which at the time of this writing, is 18.16. Doing this resolved my issue. During this issue, I was using a much older version, something like version 10.23.

like image 143
Jeremy Avatar answered Dec 02 '25 07:12

Jeremy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!