relative paths break?

Open
#3 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
javascript, nodejs
Domain
tooling

Research direction

Start with the node-hook require hook and reproduce the failure from pages/test.js at line 19, using the pass-through preprocess function shown in the issue. Check how relative module resolution behaves when .js and .jsx extensions are hooked. Done means the relative require of ../lib/site/routes works with node-hook enabled, with and without an explicit .js extension.

Written by the indexing model from the issue text.

Description

I'm using the following test code, and am getting an interesting error.

var hook = require('node-hook');
function preprocess(source, filename) {
  return source;
}
['js','jsx'].forEach(function(ext) { hook.hook('.' + ext, preprocess); });

Pretty straight-forward pass-through processing, the expectation is that this, of course, does nothing. Instead, it causes and error on the following line later in the same file (line 19 in the file) :

...
var RouteSet = require('../lib/site/routes');
...

Claiming:

module.js:328
    throw err;
    ^

Error: Cannot find module '../lib/site/routes'
    at Function.Module._resolveFilename (module.js:326:15)
    at Function.Module._load (module.js:277:25)
    at Module.require (module.js:354:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (J:\Junctions\Users\Mike\Documents\Git projects\projects\BezierInfo-2\pages\test.js:19:16)
    at Module._compile (module.js:398:26)
    at Object.Module._extensions..js (module.js:405:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Function.Module.runMain (module.js:430:10)

Without node-hook, this works just fine, it's just a relative file location, but with node-hook, things no longer work for relative requirements... I tried to change it to ../lib/sites/routes.js because maybe the automatic extension from node's site isn't kicking in, but that just gives the same error:

module.js:328
    throw err;
    ^

Error: Cannot find module '../lib/site/routes.js'
    at Function.Module._resolveFilename (module.js:326:15)
    at Function.Module._load (module.js:277:25)
    at Module.require (module.js:354:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (J:\Junctions\Users\Mike\Documents\Git projects\projects\BezierInfo-2\pages\test.js:19:16)
    at Module._compile (module.js:398:26)
    at Object.Module._extensions..js (module.js:405:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Function.Module.runMain (module.js:430:10)
Dominant language
JavaScript
Stars
66
Forks
7
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from bahmutov/node-hook

All issues in bahmutov/node-hook

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.