await import('@priv' + var); a.k.a Dynamic Third-party Namespaced Module Loading
See original GitHub issueDo you want to request a feature or report a bug? I request a godlike feature
What is the current behavior?
Here the question on StackOverflow. Sadly, no one can give me any response since one month.
Until now, I had no issue because loading something all 3rd party modules (or bundle) were explicitly defined in my package.json
and explicitly loaded in my code with full string value.
Like this :
import Bundle from '@company/bundle';
// ...
But now, my goal is to install and load those modules dynamically. I’ve already do the ‘install’ part, but I need to achieve this:
(async () => {
const something = ['/bundle']; // here for example but getted from a config file
for (const bundleName of something) {
const Bundle = await import(`@company${bundleName}`)
Bundle.doStuff();
}
})();
The current behavior is that webpack replace the import part with a webpackMissingModule
function that throw an error Cannot find module "."
.
If the current behavior is a bug, please provide the steps to reproduce.
For example with Angular (npm i @angular/core
), which has a namespace like my modules ; build and run this with a basic typescript/webpack configuration :
(async () => {
const something = ['/core'];
for (const bundleName of something) {
const angular = await import(`@angular${bundleName}`)
console.log(angular.Component);
}
})();
If you want a repo or a gist, tell me ❤️
What is the expected behavior?
I expect that my module is pre built and loaded when I ask for it even if it’s a 3rd party one.
If this is a feature request, what is motivation or use case for changing the behavior?
Bring the dynamic import to everything and not only local sources.
Please mention other relevant information such as the browser version, Node.js version, webpack version and Operating System.
- Webpack 3.8.1
- Node 9.2.1
- Yarn 1.3.2
- Typecript next
- awesome-typescript-loader latest
- OSX 10.12.6
- Chrome 63.0.3239.132 64 bits
Issue Analytics
- State:
- Created 6 years ago
- Reactions:11
- Comments:10 (4 by maintainers)
@JonathanWilbur Check out the plugin I made back then. It may need to be updated for Webpack 5 but it did the job perfectly for me.
Perhaps since this is something we have a strong intent to implement for after webpack 4, I should create a separate issue and “spec” the behavior of this feature itself, and the internal requirements.