require is incompatible with node.js when package.json/main is a directory

UNCONFIRMED
Unassigned

Status

Add-on SDK
General
--
minor
UNCONFIRMED
3 years ago
3 years ago

People

(Reporter: chocolateboy, Unassigned)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

3 years ago
User Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:38.0) Gecko/20100101 Firefox/38.0
Build ID: 20150511103818

Steps to reproduce:

OS: Linux (Ubuntu 14.04.2 LTS)
Firefox: 38.0
JPM: 1.0.0

Looking at the code in lib/toolkit/loader.js:loadAsDirectory, the issue appears to be present as of the latest commit: 3965e11c0ab53c7c2c626dd68d729ea37f2455c3.

Depend on an npm module whose package.json has a "main" entry which points to a directory e.g.:

    npm install -save stringlist

Then try to load an addon which uses that npm module e.g.:

    jpm run -b /usr/bin/firefox


Actual results:

console.error: my-addon: 
  Message: Module `stringlist` is not found at resource://gre/modules/commonjs/stringlist.js
  Stack:
    @resource://my-addon-at-example-dot-com/src/main.js:9:21
run@resource://gre/modules/commonjs/sdk/addon/runner.js:145:19
startup/</<@resource://gre/modules/commonjs/sdk/addon/runner.js:86:7
Handler.prototype.process@resource://gre/modules/Promise-backend.js:867:23
this.PromiseWalker.walkerLoop@resource://gre/modules/Promise-backend.js:746:7
this.PromiseWalker.scheduleWalkerLoop/<@resource://gre/modules/Promise-backend.js:688:37


Expected results:

The npm module's "main" entry points to a directory rather than a file [1]. If the entry point is a directory, it should resolve to dir + "index" + extension (i.e. "lib/index.js" in this case), as it does in node, and the module should load without error.

Note: the description in the node documentation [2] doesn't match the implementation [3].

[1] https://github.com/Janpot/stringlist/blob/f6f6f4073f6681e9467576c26768b6ea7181fcc2/package.json#L5
[2] https://nodejs.org/docs/v0.4.8/api/all.html#all_Together...
[3] https://github.com/joyent/node/blob/ef4344311e19a4f73c031508252b21712b22fe8a/lib/module.js#L118-L126
(Reporter)

Updated

3 years ago
Severity: normal → minor
Summary: incorrect handling of the "main" entry in the package.json file of npm modules when it points to a directory → require is incompatible with node.js when package.json/main is a directory
You need to log in before you can comment on or make changes to this bug.