Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

Unable to use import() with magic comments #34

Open
amatiash opened this issue Sep 11, 2017 · 6 comments
Open

Unable to use import() with magic comments #34

amatiash opened this issue Sep 11, 2017 · 6 comments

Comments

@amatiash
Copy link

import(/* webpackChunkName: "plugin" */ './plugin.js') sets chunk [name] the same as [id], so the output filename is 0.0.js (in config: chunkFilename: '[id].[name].js')

@ljharb
Copy link
Collaborator

ljharb commented Sep 11, 2017

This might be a duplicate of #25

@melloc01
Copy link

Same for me, I'm receiving the chunkId even with chunkFilename: [name].js and with webpackChunkName on magic comments.

@melloc01
Copy link

const setEditorUi = function () {
    const WidgetsService = require('live/services/widgets')

    import(/* webpackChunkName: "editor" */ './ui/default').then(m => WidgetsService.editor('default', m))
    import(/* webpackChunkName: "editor" */ './ui/html').then(m => WidgetsService.editor('html', m))
}

Gets transformed into:

var setEditorUi = function setEditorUi() {
    var WidgetsService = __webpack_require__(/*! live/services/widgets */ "./js/live-core/services/widgets.js");

    new Promise(function (resolve) {
        __webpack_require__.e(/*! require.ensure */ 1).then((function (require) {
            resolve(__webpack_require__( /* webpackChunkName: "editor" *//*! ./ui/default */ "./js/modules/widget/ui/default/index.js"));
        }).bind(null, __webpack_require__)).catch(__webpack_require__.oe);
    }).then(function (m) {
        return WidgetsService.editor('default', m);
    });
    new Promise(function (resolve) {
        Promise.all(/*! require.ensure */[__webpack_require__.e("vendor"), __webpack_require__.e(2)]).then((function (require) {
            resolve(__webpack_require__( /* webpackChunkName: "editor" *//*! ./ui/html */ "./js/modules/widget/ui/html/index.js"));
        }).bind(null, __webpack_require__)).catch(__webpack_require__.oe);
    }).then(function (m) {
        return WidgetsService.editor('html', m);
    });
};

@Armour
Copy link

Armour commented Aug 20, 2018

Make sure you set:

  • comments: true in .babalrc (this is the default)
  • chunkFilename: '[name].....' in your webpack config

If you are using typescript, also make sure:

  • removeComments: false under compilerOptions in tsconfig.json
  • module: esnext in tsconfig.json

This works for me and here is my commit for adding dynamic import (code split) support to my react-typescript project, hope it helps :)

@cbdyzj
Copy link

cbdyzj commented Aug 24, 2019

For TypeScript user, make sure tsconfig.json:

...
"module": "esnext",
"moduleResolution": "node",
...

@jose-bernard-receeve
Copy link

jose-bernard-receeve commented Jul 20, 2022

Make sure you set:

  • comments: true in .babalrc (this is the default)
  • chunkFilename: '[name].....' in your webpack config

If you are using typescript, also make sure:

  • removeComments: false under compilerOptions in tsconfig.json
  • module: esnext in tsconfig.json

This works for me and here is my commit for adding dynamic import (code split) support to my react-typescript project, hope it helps :)

Thank you!! it was the module": "esnext" for me

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

No branches or pull requests

6 participants