镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

createRequireFromPath does not support directories with a trailing slash #27527

Description

@MylesBorins

Follow up from e5c8be2

TL;DR

createRequireFromPath('/path/to/dir') has unexpected behavior as it is treated as a file not a directory... createRequireFromPath('/path/to/dir/') works as expected.

Seems like the only way forward would be to introduce a synchronous file / directory stat... which imho is undesirable but I totally see why this creates unexpected behavior.

/cc @BridgeAR @addaleax @devsnek

Activity

  1. self-assigned this
    on May 2, 2019
  2. mscdex commented on May 2, 2019

    @mscdex
    Contributor

    Does it really matter since that method is about to be doc-deprecated anyway (#27405)?

  3. MylesBorins commented on May 2, 2019

    @MylesBorins
    ContributorAuthor

    @mscdex since createRequire uses it under the hood the behavior is inherited.

  4. addaleax commented on May 2, 2019

    @addaleax
    Member

    This actually seems like the expected behaviour to me?

  5. Fishrock123 commented on May 13, 2019

    @Fishrock123
    Contributor

    Shouldn't createRequireFromPath() raise an error if the path is not (or does not quack like) a directory?

  6. MylesBorins commented on May 13, 2019

    @MylesBorins
    ContributorAuthor

    @Fishrock123 since it is a wrapper around new Module it actually expects a file to be passed, not a directory.

    import.meta.url for example is a file path, not directory. So if there was an error for non paths then import.meta.url would error

  7. MylesBorins commented on Jun 5, 2019

    @MylesBorins
    ContributorAuthor

    afaik this was properly fixed by ef51cc8

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