1

I have import some of my modules dynamically based on button click, i have used like below"

import { Button } from '@syncfusion/ej2-buttons';

// Initialize Button component.
let button: Button = new Button({ content: 'Button' });

// Render initialized Button.
button.appendTo('#element');

document.getElementById('element').addEventListener("click", function(){
  check();
});

async function check() {
import("@syncfusion/ej2-grids").then((Grid) => {
  debugger
  console.log(Grid);
});
}

my webpack config file:

const path = require("path");
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");

module.exports = {
  mode: "development",
  entry: {
    "src/app/bundle": "./src/app/index.ts"
  },
  output: {
    publicPath: "/js/",
    filename: "src/app/bundle.js"
  },
  devtool: "none",
  module: {
    rules: [
      {
        loader: "ts-loader",
        exclude: /node_modules/
      }
    ]
  },

  resolve: {
    extensions: [".ts", ".js"]
  }
};

when i compile and run my application it throws below error

What is the current behavior?

Throws below error error message

If the current behavior is a bug, please provide the steps to reproduce.

clone sample - https://github.com/kumaresan-subramani/dynamic-import/blob/master/webpack.config.js
run npm i
gulp compile
gulp start

Then click button in browser, you will see reported error in my console.

What is the expected behavior?

Dynamic module should load properly

Other relevant information:

"typescript": "3.7.5",
"uglifyjs-webpack-plugin": "^2.0.1",
"webpack": "^4.29.6",
"webpack-cli": "*",
"webpack-stream": "^5.2.1"
Node.js version: 10.15.1
Operating System: windows 10
1

1 Answer 1

-2

The whole logic seems weird for me. If you use a module just import it and then use it under certain conditions or after event is triggered

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.