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 resolution can fail with trailing slash #6214

Closed
targos opened this issue Apr 15, 2016 · 0 comments
Closed

module resolution can fail with trailing slash #6214

targos opened this issue Apr 15, 2016 · 0 comments
Labels
confirmed-bug Issues with confirmed bugs. module Issues and PRs related to the module subsystem.

Comments

@targos
Copy link
Member

targos commented Apr 15, 2016

  • Version: 6.0.0-rc.2 / master
  • Platform: Linux 4.5.0-302.fc24.x86_64 deps: update openssl to 1.0.1j #1 SMP Wed Mar 30 15:41:34 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
  • Subsystem: module

I discovered this bug while trying to run pm2 with v6.0.0-rc.2.

To repro, create the following directory structure:

test
test/test.js
test/node_modules/a/package.json

test/test.js:

require('a/');

test/node_modules/a/package.json:

{
  "main": "doesnotexist"
}

Then execute test/test.js.

Result with v5.10.1:

module.js:341
    throw err;
    ^

Error: Cannot find module 'a/'
    at Function.Module._resolveFilename (module.js:339:15)
    at Function.Module._load (module.js:290:25)
    at Module.require (module.js:367:17)
    at require (internal/module.js:16:19)
    at Object.<anonymous> (/home/mzasso/test/test.js:1:63)

Result with v6.0.0-rc.2 / master:

module.js:128
  for (var i = 0; i < exts.length; i++) {
                          ^

TypeError: Cannot read property 'length' of undefined
    at tryExtensions (module.js:128:27)
    at tryPackage (module.js:107:10)
    at Function.Module._findPath (module.js:182:18)
    at Function.Module._resolveFilename (module.js:434:25)
    at Function.Module._load (module.js:384:25)
    at Module.require (module.js:464:17)
    at require (internal/module.js:16:19)
    at Object.<anonymous> (/home/mzasso/test/test.js:1:63)

I'm working on a fix right now.

@targos targos self-assigned this Apr 15, 2016
@targos targos added confirmed-bug Issues with confirmed bugs. module Issues and PRs related to the module subsystem. labels Apr 15, 2016
targos added a commit to targos/node that referenced this issue Apr 19, 2016
A recent optimization of module loading performance [1] forgot to check that
extensions were set in a certain code path.

[1] nodejs@ae18bbe

Fixes: nodejs#6214
joelostrowski pushed a commit to joelostrowski/node that referenced this issue Apr 25, 2016
A recent optimization of module loading performance [1] forgot to check that
extensions were set in a certain code path.

[1] nodejs@ae18bbe

Fixes: nodejs#6214
PR-URL: nodejs#6215
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
jasnell pushed a commit that referenced this issue Apr 26, 2016
A recent optimization of module loading performance [1] forgot to check that
extensions were set in a certain code path.

[1] ae18bbe

Fixes: #6214
PR-URL: #6215
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
@targos targos removed their assignment Mar 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. module Issues and PRs related to the module subsystem.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant