ES6 import error handling

You can’t catch static imports errors (cf. Boris’ answer)

Yet, you could use a dynamic import() for that.

It’s now supported by all evergreen browsers & Node, and is part of the standards since ES2020.

class ImportError extends Error {}

const loadModule = async (modulePath) => {
  try {
    return await import(modulePath)
  } catch (e) {
    throw new ImportError(`Unable to import module ${modulePath}`)
  }
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)