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

pack.require doc is somewhat incorrect #1219

Closed
alexgorbatchev opened this issue Dec 17, 2013 · 0 comments
Closed

pack.require doc is somewhat incorrect #1219

alexgorbatchev opened this issue Dec 17, 2013 · 0 comments
Assignees
Labels
documentation Non-code related changes
Milestone

Comments

@alexgorbatchev
Copy link
Contributor

Hey friends, I listened to the recent nodeup and decided to give HAPI a try. That's what I'm doing :)

Anyways, in my attempt to build a basic modular apps using plugins, I found a misleading statement in the doc for pack.require

name - the node module name as expected by node's require(). If name is a relative path it is relative to the location of the file requiring it...

It's true that you can provide module name and it will be resolved, but it will ONLY resolve if that module is in the same node_modules folder that hapi or in any node_modules folders above...

If you have adjacent node_modules folders, require() in this case doesn't work from HAPI because it's relative to the hapi/lib/pack.js file, not the actual file I'm working on.

To give you an idea what i'm talking about, here's the folder structure of the project:

package.json
node_modules
    hapi
src
    node_modules
        client -> ../client
        server -> ../server
    client
        apps
        modules
    server
        apps
            main
                index.js
        modules

This structure allows me from index.js do require('server/apps/api') instead of having to specify relative paths everywhere. However, passing server/apps/api to pack.require does not work.

I can get around this with pack.register, so I'm not suggesting you fix the code for my edge case, but perhaps clarify the documentation in some way.

@ghost ghost assigned hueniverse Dec 21, 2013
jmonster pushed a commit to jmonster/hapi that referenced this issue Feb 10, 2014
@lock lock bot locked as resolved and limited conversation to collaborators Jan 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Non-code related changes
Projects
None yet
Development

No branches or pull requests

2 participants