Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MODULE_NOT_FOUND on Windows when requirePath is absolute #1701

Closed
garthk opened this issue Jun 10, 2014 · 1 comment
Closed

MODULE_NOT_FOUND on Windows when requirePath is absolute #1701

garthk opened this issue Jun 10, 2014 · 1 comment
Assignees
Labels
Milestone

Comments

@garthk
Copy link

@garthk garthk commented Jun 10, 2014

Root cause:

In lib/pack.js around line 500, you depend on UNIX path conventions:

        else if (itemName[0] !== '/' &&
                 self._settings.requirePath) {

Hapi then appends two absolute paths, with an inevitable MODULE_NOT_FOUND error for an invalid path.

Workaround:

The inbuilt path module lacking a cross-platform absolute path detector, I hacked this in ahead of the definition of load

    function isAbsolute(pth) {
        if (process.platform === 'win32') {
            return pth[0] === Path.sep || (pth[1] === ':' && pth[2] === Path.sep);
        } else {
            return pth[0] === Path.sep;
        }
    }

… and edited the test in load:

        else if (!isAbsolute(itemName) &&
                 self._settings.requirePath) {

I'm not sure it matches the house style, but it seems to work.

The second clause in the Windows test handles x:bar being relative to the current working directory on x:, while x:\bar is absolute.

I'm afraid I can't submit a pull request, because procedures.

@hueniverse
Copy link
Contributor

@hueniverse hueniverse commented Jun 11, 2014

This code is all gone in v6.

@hueniverse hueniverse closed this Jun 11, 2014
@hueniverse hueniverse added the bug label Jun 11, 2014
@hueniverse hueniverse added this to the 6.0.0 milestone Jun 11, 2014
@hueniverse hueniverse self-assigned this Jun 11, 2014
@lock lock bot locked as resolved and limited conversation to collaborators Jan 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants