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.

Webpack 5 incorrectly requiring @loadable/component. (Works with Webpack 4)

See original GitHub issue

💬 Questions and Help

Hello everyone! I am running into a really weird webpack 5 bug with @loadable/component. The resolved module is not being imported correctly when looking at server.js output from webpack.

Webpack 4: When bundling my code and requiring the @loadable/component package it looks like this:

/* harmony import */ var _loadable_component__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @loadable/component */ "@loadable/component");
/* harmony import */ var _loadable_component__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_loadable_component__WEBPACK_IMPORTED_MODULE_1__);

Webpack 5:

/* harmony import */ var _loadable_component__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @loadable/component */ "@loadable/component");

Why is Webpack 5 missing the second line that Webpack 4 produces? This is the only module that is having issues. Because of what Webpack 5 produces I get TypeError: _loadable_component__WEBPACK_IMPORTED_MODULE_1__ is not a function. I’ve been trying to figure out what is going wrong here for a couple days and I am stumped. Anyone have any ideas?

This is the only place I am seeing this weird behavior and I have no idea why it is happening now. I appreciate the help!

Note: All my @loadable packages are up to date.

"@loadable/babel-plugin": "^5.13.2",
"@loadable/webpack-plugin": "^5.15.1",
"@loadable/component": "^5.15.0",
"@loadable/server": "^5.15.0",

Edit: The component in question that is causing the “is not a function” error.

import React from "react";
import loadable, { DefaultComponent } from "@loadable/component";
import { LoadingPage } from "../LoadingPage";

export const loadablePage = <T extends {}>(loader: (props: T) => Promise<DefaultComponent<T>>) =>
  loadable(loader, {
    fallback: <LoadingPage />,
  });

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:3
  • Comments:11

github_iconTop GitHub Comments

2reactions
e1himselfcommented, Apr 21, 2022

@AAAstorga

There’s a working option I’ve found to unwrap an improper default export (with a different package) that you may want to try:

import loadableModule "@loadable/component";

function unwrap<T>(module: T | { __esModule: boolean; default: T }): T {
    if (typeof module === 'object' && '__esModule' in module && 'default' in module) {
        return module.default;
    }
    return module;
}

const lodable = unwrap(loadableModule);
1reaction
dagda1commented, Aug 5, 2022

the unwrap function by @e1himself fixes it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - Webpack issue when update 4.x to 5.x
So i think that there is a problem with the declaration of variable, because we have to do an Object.values() to get the...
Read more >
To v5 from v4
Webpack 5 requires at least Node.js 10.13.0 (LTS), so make sure you upgrade ... in your webpack 4 configuration and check if build...
Read more >
Server Side Rendering
const LoadablePlugin = require('@loadable/webpack-plugin') ... All scripts are loaded in parallel, so you have to wait for them to be ready using ...
Read more >
Code Splitting
Code splitting can be done in two primary ways in webpack: through a dynamic import or require.ensure syntax. The latter is so called...
Read more >
s524797336/react-loadable
Providing opts.webpack and opts.modules for every loadable component is a lot of manual work to remember to do. Instead you can add the...
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