You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PR #146 added partial support for ESM helpers, such as those using the .mjs extension. However, the loader still uses require(), which is only allowed to load ESM under limited circumstances. Notably, if a project using vision has "type": "module" in its package.json and has helpers with a .js file extension, then require() is not allowed to load them and Node will throw an ERR_REQUIRE_ESM error at:
I believe the only way to fix this is to use import() instead of require(). In recent versions of Node, import() is available within CommonJS modules and import() is capable of loading both ESM and CommonJS.
Since import() is async, it would have to be awaited, which could be problematic for the surrounding code, as it seems to be synchronous. But in principle, this should be a simple change.
What problem are you trying to solve?
I am unable to use helpers with ES module syntax and a .js file extension in a project with "type": "modele" in package.json.
Do you have a new or modified API suggestion to solve the problem?
No API changes should be necessary.
The text was updated successfully, but these errors were encountered:
Runtime
node.js
Runtime version
22.5.1
Module version
7.0.3
Used with
hapi
Any other relevant information
PR #146 added partial support for ESM helpers, such as those using the
.mjs
extension. However, the loader still usesrequire()
, which is only allowed to load ESM under limited circumstances. Notably, if a project usingvision
has"type": "module"
in its package.json and has helpers with a.js
file extension, thenrequire()
is not allowed to load them and Node will throw anERR_REQUIRE_ESM
error at:vision/lib/manager.js
Line 210 in cc598db
I believe the only way to fix this is to use
import()
instead ofrequire()
. In recent versions of Node,import()
is available within CommonJS modules andimport()
is capable of loading both ESM and CommonJS.Since
import()
is async, it would have to be awaited, which could be problematic for the surrounding code, as it seems to be synchronous. But in principle, this should be a simple change.What problem are you trying to solve?
I am unable to use helpers with ES module syntax and a
.js
file extension in a project with"type": "modele"
in package.json.Do you have a new or modified API suggestion to solve the problem?
No API changes should be necessary.
The text was updated successfully, but these errors were encountered: