Skip to content

Can throw ENOTDIR instead of MODULE_NOT_FOUND #121

Closed

Description

@loganfsmyth
require('./CHANGELOG.md/directory');

will throw code MODULE_NOT_FOUND, but

require('resolve').sync('./CHANGELOG.md/directory')

will throw code ENOTDIR.

Activity

  1. ljharb commented on Mar 12, 2017

    @ljharb
    Member

    The comparison would be to require.resolve, not to require, but I suspect that's a red herring.

    What filesystem setup and resolve version are you getting ENOTDIR with? I can't reproduce it - everything gives me MODULE_NOT_FOUND.

  2. loganfsmyth commented on Mar 12, 2017

    @loganfsmyth
    Author

    Right, true enough about the example.

    My setup was just in the root of the Babel repo, in this case with CHANGELOG.md being a file in the current directory. Should reproduce in a empty dir with

    touch CHANGELOG.md
    node -e "require('resolve').sync('./CHANGELOG.md/directory')"
    
  3. ljharb commented on Mar 12, 2017

    @ljharb
    Member

    Thanks, with a filename that exists, I get the following:

    > try { require('./').sync('./FILENAME/'); } catch (e) { e.code; }
    '$PWD/FILENAME'
    
    > try { require('./').sync('./FILENAME/dir'); } catch (e) { e.code; }
    'ENOTDIR'
    

    require.resolve, in both cases, gives MODULE_NOT_FOUND.

    The former is a bug, the latter is a deviation (arguably a more useful variant) - but since require.resolve doesn't do that, we shouldn't either.

  4. self-assigned this
    on Mar 12, 2017
  5. ljharb commented on Mar 12, 2017

    @ljharb
    Member

    Of note, this seems to only happen when the basedir option is not provided.

  6. loganfsmyth commented on Mar 12, 2017

    @loganfsmyth
    Author

    I first ran across it when using a basedir, but it appears to happen with or without for me.

  7. added a commit that references this issue on Mar 19, 2017
    2d973d5
  8. ljharb commented on Mar 19, 2017

    @ljharb
    Member

    @loganfsmyth could you give this branch a try? It includes both a fix, and a (hopefully insignificant) breaking change, which should bring resolve in line with require.resolve for these kinds of scenarios.

  9. loganfsmyth commented on Apr 4, 2017

    @loganfsmyth
    Author

    Looks good to me, thanks! Sorry it took so long to get back to this.

  10. ljharb commented on Apr 5, 2017

    @ljharb
    Member

    @loganfsmyth thanks!

  11. added a commit that references this issue on Apr 5, 2017
    98e5b0a
  12. added 2 commits that reference this issue on Apr 19, 2017
    5e9d428
    f009822
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions