Node: Better not found errors for ESM

Created on 22 Nov 2019  路  5Comments  路  Source: nodejs/node

When not using a file extension in ESM - eg import pkg from './path' we currently just throw a straightforward not found error. As proposed by @MylesBorins in https://github.com/nodejs/modules/issues/443 it would be useful to enhance this error message.

Ideally the error message should run the CJS resolver and say "the CJS resolver would have resolved this module to ...". We actually previously had this code path implemented by @bmeck but it seems to have got lost along the way. See the early implementation at https://github.com/nodejs/node/pull/14369/files#diff-3e94629c67625a2547d1507d0a547211R20.

Sorry @bmeck I think I might have dropped this and forgot to add it back when refactoring error codes to be standard. That was bad.

ES Modules feature request good first issue help wanted

All 5 comments

I have the same issue with ESM "type": "module": extensionless files are not resolved

I think I could help with this

I quite lost with this issue, which Module method should I use? I was trying with Module._resolveFilename, but I'm having troubles with parent, parent url is file://whatever and not an instance of Module

I need some help D:

PR #30699

Resolved in #31906 thanks for @dnlup.

Was this page helpful?
0 / 5 - 0 ratings