Opening the node repl (v6.6.0) and doing:
> const test = require('somethingGuaranteedToFail');
Error: Cannot find module 'somethingGuaranteedToFail'
> console.log(typeof test);
ReferenceError: test is not defined
> const test = 1;
TypeError: Identifier 'test' has already been declared
I guess the question is, is this expected behaviour?
Yes. A const cannot be redefined or redeclared.
const test declared it, but failed to define it because an error was raised.
I would have thought the const variable would at least contain the
require does not return an error, it throws one. If you want it, you need to