Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when doing SSR and webpack serve (webpack 5) #657

Closed
oreqizer opened this issue Nov 5, 2020 · 6 comments
Closed

Error when doing SSR and webpack serve (webpack 5) #657

oreqizer opened this issue Nov 5, 2020 · 6 comments

Comments

@oreqizer
Copy link
Contributor

oreqizer commented Nov 5, 2020

🐛 Bug Report

When webpack (5.3.2, works OK on 4.x.x) is run in serve mode with webpack-dev-server, I get the following error:

loadable.esm.js:277 loadable-components: failed to synchronously load component, which expected to be available 
{fileName: "./src/app/pages/Index/index.tsx", chunkName: "pages-Index", error: "Cannot read property 'call' of undefined"}
chunkName: "pages-Index"
error: "Cannot read property 'call' of undefined"
fileName: "./src/app/pages/Index/index.tsx"
__proto__: Object

When I just build using webpack --mode production and run production server, all is OK.

This is my webpack config (the rest is in @reactizer/webpack but nothing really important, I tried adjusting all values without difference, the only difference is serve):

const path = require("path");
const reactizer = require("@reactizer/webpack");
const webpack = require("webpack");
const dotenv = require("dotenv-safe");
const { merge } = require("webpack-merge");
const LoadablePlugin = require("@loadable/webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const SentryPlugin = require("@sentry/webpack-plugin");

const env = dotenv.config({
  allowEmptyValues: true,
  path: ".env",
  example: ".env.example",
}).required;

module.exports = (e, argv) => {
  const production = argv.mode === "production";

  const cfg = reactizer(e, argv);

  // Remove styled-components specific things
  // eslint-disable-next-line fp/no-mutation
  cfg.module.rules = cfg.module.rules
    .filter((r) => String(r.test) !== String(/\.tsx?$/))
    .filter((r) => String(r.test) !== String(/\.css$/));

  const base = {
    resolve: {
      fallback: { path: false },
    },
    entry: {
      app: path.resolve(__dirname, "src/app/index.ts"),
    },
    plugins: [
      new webpack.EnvironmentPlugin(env),
      // https://github.com/vfile/vfile/issues/38
      new webpack.ProvidePlugin({
        process: "process/browser",
      }),
      new LoadablePlugin({
        writeToDisk: { filename: "dist" },
      }),
      new MiniCssExtractPlugin({
        filename: production ? "[name].[contenthash:8].css" : "[name].css",
        chunkFilename: production ? "[name].[contenthash:8].css" : "[name].css",
        ignoreOrder: true,
      }),
      env.SENTRY_RELEASE &&
        new SentryPlugin({
          release: env.SENTRY_RELEASE,
          include: "src",
          ext: ["ts", "tsx"],
        }),
    ].filter(Boolean),
    module: {
      rules: [
        {
          test: /\.tsx?$/,
          use: [
            "babel-loader",
            {
              loader: "linaria/loader",
              options: {
                sourceMap: !production,
              },
            },
          ],
          exclude: /node_modules/,
        },
        {
          test: /\.css$/,
          use: [
            {
              loader: MiniCssExtractPlugin.loader,
              options: {
                hmr: !production,
              },
            },
            {
              loader: "css-loader",
              options: {
                sourceMap: !production,
                url: false,
              },
            },
            "postcss-loader",
          ],
        },
      ],
    },
  };

  if (production) {
    return merge(cfg, base, {
      output: {
        path: path.resolve(__dirname, "dist/static"),
      },
    });
  }

  return merge(cfg, base, {
    output: {
      path: path.resolve(__dirname, ".tmp/static"),
    },
    devServer: {
      contentBase: false,
      compress: true,
    },
  });
};

To Reproduce

Steps to reproduce the behavior:

Do a dev server using webpack serve, try having a component using loadable(() => import("...")); and render using loadableReady(() => ...);

Expected behavior

The error should not happen and app should run.

Run npx envinfo --system --binaries --npmPackages @loadable/component,@loadable/server,@loadable/webpack-plugin,@loadable/babel-plugin --markdown --clipboard

Paste the results here:

## System:
 - OS: macOS 10.15.4
 - CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
 - Memory: 806.82 MB / 16.00 GB
 - Shell: 5.8 - /usr/local/bin/zsh
## Binaries:
 - Node: 14.4.0 - /usr/local/bin/node
 - Yarn: 1.22.10 - ~/gainwagon/web/node_modules/.bin/yarn
 - npm: 6.14.4 - /usr/local/bin/npm
 - Watchman: 4.9.0 - /usr/local/bin/watchman
## npmPackages:
 - @loadable/babel-plugin: ^5.13.2 => 5.13.2 
 - @loadable/component: ^5.14.1 => 5.14.1 
 - @loadable/server: ^5.14.0 => 5.14.0 
 - @loadable/webpack-plugin: ^5.14.0 => 5.14.0 
@open-collective-bot
Copy link

Hey @oreqizer 👋,
Thank you for opening an issue. We'll get back to you as soon as we can.
Please, consider supporting us on Open Collective. We give a special attention to issues opened by backers.
If you use Loadable at work, you can also ask your company to sponsor us ❤️.

@oreqizer oreqizer changed the title Error when doing SSR and webpack --serve (webpack 5) Error when doing SSR and webpack serve (webpack 5) Nov 5, 2020
@theKashey
Copy link
Collaborator

Webpack 5 is not yet properly supported #636

@stale
Copy link

stale bot commented Jan 4, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jan 4, 2021
@stale stale bot closed this as completed Jan 12, 2021
@theKashey theKashey reopened this Jan 12, 2021
@stale stale bot removed the wontfix label Jan 12, 2021
@stale
Copy link

stale bot commented Mar 16, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Mar 16, 2021
@stale stale bot closed this as completed Mar 26, 2021
@dmitryshelomanov
Copy link

any solutions ? @oreqizer

@oreqizer
Copy link
Contributor Author

it was fixed in the meantime @dmitryshelomanov

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants