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. Error: TypeError: TypeError: Cannot read property 'data' of undefined

See original GitHub issue

im in the process of updating all the module federation repos to the final v5

Ive run into issues with svelt-loader, but know very little about svelte…

This is the branch and specific project im trying to run this against: https://github.com/module-federation/module-federation-examples/blob/update-to-v5-stable/comprehensive-demo/app-04/webpack.config.js

[0] @comprehensive-demo/app-04: ERROR in ./src/App.svelte
[0] @comprehensive-demo/app-04: Module build failed (from ./node_modules/svelte-loader/index.js):
[0] @comprehensive-demo/app-04: Error: TypeError: TypeError: Cannot read property 'data' of undefined
[0] @comprehensive-demo/app-04:     at /Volumes/lulu_dev/module-federation-examples/comprehensive-demo/app-04/node_modules/svelte-loader/index.js:181:12
[0] @comprehensive-demo/app-04:  @ ./src/main.js 1:0-31 3:16-19 11:13-16

And my webpack config is:

const HtmlWebpackPlugin = require("html-webpack-plugin");
const ModuleFederationPlugin = require("webpack").container
  .ModuleFederationPlugin;
const deps = require("./package.json").dependencies;
module.exports = {
  entry: "./src/index",
  cache: false,

  mode: "development",
  devtool: "source-map",

  optimization: {
    minimize: false,
  },

  output: {
    publicPath: "auto",
  },

  resolve: {
    extensions: [".jsx", ".js", ".json",".mjs"],
  },

  module: {
    rules: [
      { test: /\.m?js$/, type: "javascript/auto" },
      {
        test: /\.jsx?$/,
        loader: require.resolve("babel-loader"),
        exclude: /node_modules/,
        options: {
          presets: [require.resolve("@babel/preset-react")],
        },
      },
    ],
  },

  plugins: [
    new ModuleFederationPlugin({
      name: "app_02",
      filename: "remoteEntry.js",
      remotes: {
        app_01: "app_01@http://localhost:3001/remoteEntry.js",
        app_03: "app_03@http://localhost:3003/remoteEntry.js",
      },
      exposes: {
        "./Dialog": "./src/Dialog",
        "./Tabs": "./src/Tabs",
      },
      shared: {
        ...deps,
        "@material-ui/core": {
          singleton: true,
        },
        "react-router-dom": {
          singleton: true,
        },
        "react-dom": {
          singleton: true,
        },
        react: {
          singleton: true,
        },
      },
    }),
    new HtmlWebpackPlugin({
      template: "./public/index.html",
      chunks: ["main"],
    }),
  ],
};

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:28 (3 by maintainers)

github_iconTop GitHub Comments

13reactions
Smittyvbcommented, Nov 10, 2020

@carsonfarmer Disable emitCss (if it is enabled) and add this to your config, this works for me:

  module: {
    rules: [
      ...
      {
        test: /node_modules\/svelte\/.*\.mjs$/,
        resolve: {
          fullySpecified: false // load Svelte correctly
        }
      },
      ...
    ]
  }
7reactions
kyrylkovcommented, Jan 6, 2021

@Smittyvb @benmccann @deleonio @lindenquan

Is there a plan to accept PRs and finalize fixes for webpack 5 anytime soon? thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Runtime error appeared after updating to webpack 5. TypeError
Runtime error appeared after updating to webpack 5. TypeError: Cannot read properties of undefined (reading 'default') ; In config.output.
Read more >
typeerror: cannot read property 'descendant' of undefined
That is, the primary problem being: TypeError: Cannot read property 'properties' of undefined. The best solution I've found to the problem is to...
Read more >
TypeError: Cannot read property 'data' of undefined
This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not...
Read more >
Uncaught TypeError: Cannot read property of undefined In
JavaScript TypeError is thrown when an operand or argument passed to a function is incompatible with the type expected by that operator or...
Read more >
How To Fix Cannot read Property '0' of Undefined in JS
So why are you getting the TypeError mentioned above? You have most likely attempted to access your variable's contents while that variable has ......
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