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.

Annotated dynamic import causes crash

See original GitHub issue

When using webpack annotations for dynamic imports, madge tries to make sense of the first argument to the import, which will be undefined.

So:

const Graph =  React.lazy(() => import(/* webpackChunkName: 'react-graph-vis' */ `react-graph-vis`))

causes

✖ TypeError: Cannot read property 'lastIndexOf' of undefined
    at Object.startsWith (/Users/torgeir/dev/signatu/signatu/node_modules/typescript/lib/typescript.js:2025:20)
    at mangleScopedPackageName (/Users/torgeir/dev/signatu/signatu/node_modules/typescript/lib/typescript.js:27283:16)
    at mangleScopedPackageNameWithTrace (/Users/torgeir/dev/signatu/signatu/node_modules/typescript/lib/typescript.js:27270:23)
    at loadModuleFromImmediateNodeModulesDirectory (/Users/torgeir/dev/signatu/signatu/node_modules/typescript/lib/typescript.js:27195:83)
    at /Users/torgeir/dev/signatu/signatu/node_modules/typescript/lib/typescript.js:27172:39
    at Object.forEachAncestorDirectory (/Users/torgeir/dev/signatu/signatu/node_modules/typescript/lib/typescript.js:12577:26)
    at loadModuleFromNearestNodeModulesDirectoryWorker (/Users/torgeir/dev/signatu/signatu/node_modules/typescript/lib/typescript.js:27166:19)
    at loadModuleFromNearestNodeModulesDirectoryTypesScope (/Users/torgeir/dev/signatu/signatu/node_modules/typescript/lib/typescript.js:27162:16)
    at tryResolve (/Users/torgeir/dev/signatu/signatu/node_modules/typescript/lib/typescript.js:27348:28)
    at classicNameResolver (/Users/torgeir/dev/signatu/signatu/node_modules/typescript/lib/typescript.js:27324:24)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:13
  • Comments:15 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
devinrhode2commented, Oct 6, 2020

Just change all the dynamic import( calls to be static import statements at the top, run madge, git stash the conversion of import( calls (or put it on a branch).

2reactions
Zjaaspoercommented, Jun 14, 2019

Getting the same issue, typescripts import(...) gives the above mentioned error

Read more comments on GitHub >

github_iconTop Results From Across the Web

Annotated dynamic import should not cause crash package ...
This issue is originated from madge pahen/madge#211 mangeScopedPackageName function crashes when madge is running classicNameResolver ...
Read more >
Dynamic Import, Code Splitting, Lazy Loading, and Error ...
This article is a detailed guide on how to use dynamic import, which enables code splitting and lazy loading. It also describes how...
Read more >
How to prevent typescript from transpiling dynamic imports ...
Since require() can't import ESM modules, my bot ends up crashing. I tried however to stop my ts compiler, copy the code from...
Read more >
When Things Go Wrong — PyInstaller 5.7.0 documentation
Analysis creates a message when it detects an import and the module it names cannot be found. A message may also be produced...
Read more >
Fixed issues in Premiere Pro versions 23.x and 22.x
Fixed issues that could cause: All files from Canon cinema cameras to be imported with the clip name CLIPS001. A crash while adjusting...
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