Skip to content

safeRequire returning undefined even when module is installed #833

Closed

Description

@ritch

We're running into an issue where the following setup is causing
https://github.com/strongloop/loopback/blob/master/lib/express-middleware.js#L8 to return undefined.

arc depends on loopback
arc depends on workspace
workspace depends on loopback
workspace depends on cookie-parser

Since the versions are compatible (I assume) npm installs only one loopback package in arc's node_modules directory (and nothing in workspace). This breaks the assumptions safeRequire() makes - which is that the loopback will be a dependency of the module that has the independent middleware installed (eg. serve-favicon, which is installed in workspace).

I'm not exactly sure how we can fix this with npm's behavior. Npm chooses to install only a single loopback module. Currently we just install the modules in arc. This is a bit unsettling because they are not arc's dependencies (they are workspace's).

Activity

  1. bajtos commented on Nov 19, 2014

    @bajtos
    Member

    I think the correct fix is to stop using loopback.{name} shortcuts and load the middleware directly via require. See strongloop/loopback-workspace#166 for an example of such change.

    It would be even better to 1) upgrade loopback-workspace to use the new 2.x project layout 2) convert it to a proper loopback component, so that strong-arc can import workspace models into the main strong-arc app.

  2. bajtos commented on Nov 19, 2014

    @bajtos
    Member

    BTW I have run into the same problem when I was npm link-ing loopback to a different project. Node module lookup uses the real path (e.g. ~/src/loopback), not the symlink path (e.g. ~/src/loopback-boot/node_modules/loopback) and thus it look into ~/src/loopback-boot/node_modules when resolving require called from loopback.

    We should use as much middleware as we can directly, and use loopback shortcuts only where necessary: loopback.static and loopback.favicon.

  3. bajtos commented on Jan 16, 2015

    @bajtos
    Member

    I believe this issue is a duplicate of strongloop/loopback-boot#73

  4. bajtos commented on Apr 16, 2015

    @bajtos
    Member

    This should be fixed as of loopback-boot@2.7.0. Please upgrade your projects to use this new version and reopen this issue if the problem still persists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions