[Insights](/insights/) / [Core Engineering Intelligence](/insights/core_engineering_intelligence/)

# Fix "imported module is not a function" after moving to webpack 5

Why a library's default import breaks with "is not a function" after a webpack 5 build, and the small config fix for library authors.

![Ivan Borshchov](https://static.devforth.io/adminusers/avatars/2026/48db9847-d461-40cd-b344-f2bd7b0d98ca-avatar_ivan@devforth.io_f4ce9df9-8363-4314-9345-28753c76a386.jpeg)

Ivan Borshchov

CEO & System Architect @ DevForth

Dec 3, 2026

![Fix "imported module is not a function" after moving to webpack 5](https://static.devforth.io/posts/logo-svg/2026/4ece3224-d122-4007-9291-35d22773e0f9-logo-preview-new.svg)

![Fix "imported module is not a function" after moving to webpack 5](https://static.devforth.io/posts/logo-svg/2026/4ece3224-d122-4007-9291-35d22773e0f9-logo-preview-new.svg)

You moved a library to webpack 5 and published it. Now the apps that use it crash with:

```
TypeError: mylib__WEBPACK_IMPORTED_MODULE_0___default(...) is not a function
```

Explained like you're five: the app asked for a toy, got a box with the toy inside, and tries to play with the box.

**Why it happens**

Look at the library's webpack config. This one is very common:

```javascript
output: {
  filename: 'mylib.commonjs2.js',
  library: 'MyLib',
  libraryTarget: 'commonjs2',
},
```

Webpack 4 ignored the name `MyLib` for `commonjs2` builds and put your code straight into `module.exports`. Webpack 5 does what its docs say: with a name set, your code goes to `module.exports.MyLib`. So `import MyLib from 'mylib'` now gets the box `{ MyLib: ... }` instead of the function.

**The fix, for library authors**

Drop the name from the CommonJS build:

```javascript
output: {
  filename: 'mylib.commonjs2.js',
  library: { type: 'commonjs2' },
},
```

Rebuild and publish a patch version, and the old imports work again. If your entry uses `export default` and you also want `require('mylib')` to return it directly, add `export: 'default'` to the `library` object.

**A quick workaround, for library users**

Until the library is fixed, check what you actually receive:

```javascript
import * as mylib from 'mylib'
console.log(mylib)
```

The function is in there somewhere, usually under the library's name. Call it from there, or pin the last version that worked, and send the author a link to this fix.

In short: in webpack 5, `commonjs2` plus a library name wraps your export in an object. Remove the name and the default import works again.

## Get your project quote

Free result within 48-72 hours

[

Get a quote

](/estimation-request/)[

Talk to our engineers

](https://talk.devforth.io/book/30-minute-meeting)

[

Back to insights

](/insights/)

[](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fdevforth.io%2Finsights%2Ffix-imported-module-is-not-a-function-after-moving-to-webpack-5%2F)[](https://bsky.app/intent/compose?text=Fix%20%22imported%20module%20is%20not%20a%20function%22%20after%20moving%20to%20webpack%205%0A%0Ahttps%3A%2F%2Fdevforth.io%2Finsights%2Ffix-imported-module-is-not-a-function-after-moving-to-webpack-5%2F)[](https://x.com/intent/tweet?text=Fix%20%22imported%20module%20is%20not%20a%20function%22%20after%20moving%20to%20webpack%205%20by%20%40ivanborshchov%0A%0Ahttps%3A%2F%2Fdevforth.io%2Finsights%2Ffix-imported-module-is-not-a-function-after-moving-to-webpack-5%2F)

## Related insights

[

![What to do when an open-source package is no longer maintained](https://static.devforth.io/posts/logo-svg/2026/e2463731-0f3e-49ba-95d2-adfb8e02e0aa-logo-preview-new.svg)

Core Engineering Intelligence Dec 3, 2026

## What to do when an open-source package is no longer maintained

A short checklist for an abandoned npm or pip dependency. Confirm it's abandoned, find a maintained fork, check the license and switch safely.

](/insights/what-to-do-when-an-open-source-package-is-no-longer-maintained/)[

![How to back up a SQL database so it actually works](https://static.devforth.io/posts/logo-svg/2026/f7a30c3e-5083-4833-9a05-3373d5de76b1-logo-preview-new.svg)

Core Engineering Intelligence Dec 3, 2026

## How to back up a SQL database so it actually works

A simple backup routine for PostgreSQL and MySQL. Dump the data, copy it off the server, run it on a schedule and check that you can restore.

](/insights/how-to-back-up-a-sql-database-so-it-actually-works/)[

![Forward a remote port to your computer with SSH](https://static.devforth.io/posts/logo-svg/2026/62b2a6d3-714d-471d-864e-c48d51d84d77-logo-preview-new.svg)

Core Engineering Intelligence Dec 3, 2026

## Forward a remote port to your computer with SSH

Use ssh -L to open a database, admin panel or debug server that runs on a remote server on your own localhost, without opening it to the internet.

](/insights/forward-a-remote-port-to-your-computer-with-ssh/)
