Error: Cannot find module with dynamic import
See original GitHub issueDo you want to request a feature or report a bug?
bug
What is the current behavior?
When I try to load dynamic module with import('/path/to/my/module.js').then() it work, but when i try to import module with import(rootPath + '/' + myModuleName + '/index.js').then() it doesn’t work.
I got:
Error: Cannot find module '/Users/hubert_i/Emodyz/launcher-ezgames.eu/modules/test/index.js'.
at /Users/hubert_i/Emodyz/launcher-ezgames.eu/dist/electron/main.js:10475:9
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
If the current behavior is a bug, please provide the steps to reproduce.
What is the expected behavior?
Dynamic import with variable
Please mention other relevant information such as the browser version, Node.js version, webpack version, and Operating System.
webpack => 3.10.0 npm => 5.6.0 yarn => 1.5.1 Node.js => v9.6.1 Operating System => macOs High Sierra
Issue Analytics
- State:
- Created 6 years ago
- Reactions:29
- Comments:30 (3 by maintainers)
Top Results From Across the Web
Uncaught Error: Cannot Find Module When Using Dynamic ...
Fully dynamic statements, such as import(foo), will fail because webpack requires at least some file location information.The import() must ...
Read more >Error: Cannot find module with dynamic import - Allen Kim
If you want component name as a variable const imported: any = await import(`./${name}. component`); const komponent = imported[`MyComponent`]; const ...
Read more >Module Methods - webpack
A normal import statement cannot be used dynamically within other logic or contain variables. See the spec for more information and import() below...
Read more >@rollup/plugin-dynamic-import-vars - npm
Resolving dynamic imports that contain variables.. Latest version: 2.0.2, last published: 10 days ago.
Read more >Uncaught Error: Cannot Find Module When Using Dynamic ...
[Solved]-Uncaught Error: Cannot Find Module When Using Dynamic Import for JavaScript-Reactjs ... Only partially dynamic statement are allowed for import().
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Webpack performs a static analyse at build time. It doesn’t try to infer variables which that
import(test)could be anything, hence the failure. It is also the case forimport(path+"a.js").If you need truly dynamic imports, you have to restrict it to a known path:
In the above example, webpack will create a chunk for each JS file in
locale/.It’s incomprehensible 😢
If i write this it work
but when i write this don’t work