I am currently using Babel.
I did the following with require :
try { var myModule = require('my-module'); } catch (err) {
However, when trying to do this with import :
try { import myModule from 'my-module'; } catch (err) {
I get an error message:
'import' and 'export' can only be displayed at the top level
Now I understand that import is different from require . Read Read Are ES6 module modules imported? import , which means that the import is loaded before the code runs.
What I did before was that if any request is not executed, a log is created that alerts me by email (sending logs to logstash, etc.). Therefore, my question boils down to the following.
How to handle import errors in good practice mode in nodes? Is there such a thing?
source share