question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

If an explicit cwd is provided, try searching for the module there if it could otherwise not be determined

See original GitHub issue

The current implementation chooses to search for the module in the following order:

  1. <configPath directory>/node_modules/<module name>
  2. main file in <configPath directory>/package.json

I have a need for the search to continue. Perhaps if these first two searches turn out unsuccessful, these 2 steps could be repeated in the CWD (in place of the configPath) if an explicit one was provided. So the process would be to search for the module in the following order:

  1. <configPath directory>/node_modules/<module name>
  2. main file in <configPath directory>/package.json
  3. <provided cwd>/node_modules/<module name>
  4. main file in <provided cwd>/package.json

Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
grahamajcommented, Oct 7, 2015

This is true, but is not the case when a configPath is set.

In my specific situation, I have a configPath file that is version controlled in directory A and want to run it in context of directory B which is not version controlled. Directory B contains my target library in the node_modules directory. I expected that when I pass both the configPath and the cwd that it would search for my target library in directory B since I explicitly told it that I am working there. What happens instead is that it only tries to look for the target library in directory A. This is because configBase is defined and so the said line of code (https://github.com/js-cli/js-liftoff/blob/master/index.js#L93) chooses to assign configBase to the basedir property. The node_modules aren’t there and neither is a package.json file. This directs to code to https://github.com/js-cli/js-liftoff/blob/master/index.js#L110 where the modulePath is never assigned.

I realize that in most cases the configPath file will be co-located with the target library, but I also see no harm in searching the cwd path after the configPath directory is searched and the code failed to locate an appropriate modulePath.

0reactions
ams-tschoeningcommented, Nov 4, 2019

I’ve ran into the same problem with the following directory layout:

  • app
  • build
  • config
    • Gruntfile.js
    • stealConfig.js
  • lib
    • bower_components
    • node_modules
    • bower.json
    • package.json

Grunt uses LiftOff these days like the following:

  Grunt.launch({
    cwd: options.base,
    configPath: options.gruntfile,
    require: options.require,
    verbose: options.verbose
  }, function (env) {

But had the same problem in the past on its own as well. The workaround then was to simply set the current working dir of the process:

gruntpath = findup('lib/grunt.js');

With switching to LiftOff this doesn’t work anymore and the current working directory is not recognized during searching for modules, even though it’s provided on the shell using --base (or even --cwd). But one can work around that using package.json in the config-dir: That file is always checked in case a configBase is available, but a requested module has not been found and only needs to contain the following in my directory layout:

{
	"name": "grunt",
	"main": "../lib/node_modules/grunt"
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Command-line parameter to force "module" instead ... - GitHub
I'm aware that I can name a file with .mjs or set "type": "module" in package.json. I'm also aware of the --input-type=module CLI...
Read more >
How can I import a module dynamically given the full path?
The python path can contain zip archives, "eggs" (a complex kind of zip archives), etc. Modules can be imported out of them. So...
Read more >
subprocess — Subprocess management — Python 3.11.1 ...
The subprocess module allows you to spawn new processes, connect to their ... If capture_output is true, stdout and stderr will be captured....
Read more >
Python Tutorial - File and Text Processing
When a module is loaded in Python, __file__ is set to the module name. Try running this script with various __file__ references and...
Read more >
query, download and build perl modules from CPAN sites
If it is a module, CPAN determines the distribution file in which this ... only lists directories explicitly asked for, for example FOO/*...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found