Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

257
Views
import() use static string work well but string variable not work.And throwing error "Error: Cannot find module 'xxx module path'"

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?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!