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

Fails to bundle modules with dynamic imports #1110

Closed
weagle08 opened this issue Jun 4, 2019 · 4 comments
Closed

Fails to bundle modules with dynamic imports #1110

weagle08 opened this issue Jun 4, 2019 · 4 comments

Comments

@weagle08
Copy link

weagle08 commented Jun 4, 2019

I'm submitting a feature request

  • Library Version:
    1.0.0-beta.15

Please tell us about your environment:

  • Operating System:
    Windows 10

  • Node Version:
    10.15.0

  • NPM Version:
    6.4.1

  • Browser:
    Chrome XX

  • Language:
    TypeScript 3.3

  • Loader/bundler:
    SystemJS

Current behavior:

Fails to bundle modules which use dynamic imports (amcharts4 is the problematic library)

ERROR [BundledSource] Could not convert to AMD module, skipping D:\dev\stock-screener-client\node_modules\@amcharts\amcharts4\.internal\core\export\Export.js
ERROR [BundledSource] Error was: SyntaxError: unknown: Support for the experimental syntax 'dynamicImport' isn't currently enabled (68:25):

  66 |             switch (_a.label) {
  67 |                 case 0: return [4 /*yield*/, Promise.all([
> 68 |                         import(/* webpackChunkName: "pdfmake" */ "pdfmake/build/pdfmake.js"),
     |                         ^
  69 |                         import(/* webpackChunkName: "pdfmake" */ "../../pdfmake/vfs_fonts")
  70 |                     ])];
  71 |                 case 1:

Add @babel/plugin-syntax-dynamic-import (https://git.io/vb4Sv) to the 'plugins' section of your Babel config to enable parsing.
ERROR [Bundler] Failed to do transforms
  • What is the expected behavior?
    modules with dynamic imports should succeed

  • What is the motivation / use case for changing the behavior?
    Would like the ability to use amcharts4 as a module instead of just imported script. I attempted to add the @babel/plugin-syntax-dynamic-import to the cli in the only location I found babel plugins being specified in lib/build/amodro-trace/read/es.js to no avail. Where can I import this plugin for use? or does the systemjs bundler not even use babel? I know the code piece I posted says webpack, but I'm using the SystemJS bundler.

Thanks,

Ben

@3cp
Copy link
Member

3cp commented Jun 4, 2019

cli-bundler doesn't support dynamic import for now mainly because esprima has not released the feature jquery/esprima#1728. (Beside the babel thing to transpile esm module, cli-bundler needs to use esprima to analysis deps too)

The amcharts4 code looks assume it's consumed in webpack app too. If you move to webpack, beware the dynamic import has some issue on latest webpack https://www.amcharts.com/docs/v4/getting-started/integrations/using-webpack/

@3cp
Copy link
Member

3cp commented Jun 4, 2019

If you want to avoid webpack, there is the WIP successor of cli-bundler, called dumber bundler I am working on. It's stable enough I am running all my production apps with it. The bad part is the doc is unfinished.

The new bundler solved various shortages (including dynamic import()) of cli-bundler due to architecture issue.

If you want to have a look, you can create a new app with npx makes dumberjs (just run the command, no tool installation required).

Here is a demo app of aurelia+amcharts4+dumber, created by the above command.
https://github.com/3cp/demo-aurelia-amcharts4-dumber

The amcharts4 package has some issue on its source map files, but that doesn't stop anything.

@weagle08
Copy link
Author

weagle08 commented Jun 5, 2019

Thanks for the explanation. I prefer to stay away from webpack. I just do not like it from my experience with it using Angular. For now I can just import the am4charts globally in my index.html and all works fine, just no intellisense for typescript.

@weagle08 weagle08 closed this as completed Jun 5, 2019
@kanhaiyaSalez
Copy link

Hi Guys use below steps will solve the issues.

npm install --save acorn@6.1.1
npm dedupe

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

No branches or pull requests

3 participants