When using webpack for code separation, dynamically importing the import () browser reports an error

page.js is as follows. Import other modules in page.js through import () syntax

import(/* webpackChunkName: "subPageA"*/ "./subPageA").then(function(subPageA) {
  console.log(subPageA);
});

import(/* webpackChunkName: "subPageB"*/ "./subPageB").then(function(subPageB) {
  console.log(subPageB);
});

import(/* webpackChunkName: "lodash"*/ "lodash").then(function(_) {
  console.log(_.join(["1", "2"]));
});

webpack.config.js is as follows:

const webpack = require("webpack");
const path = require("path");

module.exports = {
  mode:"development",
  entry: {
    page: "./src/page.js" //
  },
  output: {
    publicPath: __dirname + "/dist/",
    path: path.resolve(__dirname, "dist"),
    filename: "[name].bundle.js",
    chunkFilename: "[name].chunk.js"
  }
};

error message:


official documentation indicates that browsers are required to support promise features, but my chrome is the latest version 71 and definitely supports promise.

I also tried to use the server to get resources, and the same error occurred.

Apr.18,2022

Sorry to bother you, but the problem lies in the out.publicPath configuration of webpack, which causes the browser file to introduce the wrong path

For more information, please see https://webpack.docschina.org...

.
Menu