You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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
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 anynode_modules
folders above...If you have adjacent
node_modules
folders,require()
in this case doesn't work from HAPI because it's relative to thehapi/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:
This structure allows me from
index.js
dorequire('server/apps/api')
instead of having to specify relative paths everywhere. However, passingserver/apps/api
topack.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.The text was updated successfully, but these errors were encountered: