Using static import mode works well.For example:
import App from './App.js';
And in common general style of using "import()" works well:
async function fun(){
const App = async ()=> await import("./App.js");
console.log(await App() )//it load module successfully
}
fun();
When i use a string variable parameter for import(),it dosn't work.And it will throw error:
async function fun(){
const path = "./App.js";
const App = async ()=> await import(path).catch(err=>console.log(err));
await App() //Error: Cannot find module 'xxx module path'
}
fun();
So,i must load all modules before using.Could i dynamic import modules like that demo?
I go through the mdn docs about dynamic import but not get helpful information.
And require() performs the same.
Does someone have the same questions?
You need to use ./ and not ../, as ../ is the parent directory and not the current directory. I don't know why this only applies to dynamic imports, but thats just some weird thing about it.