GithubHelp home page GithubHelp logo

Comments (5)

philidem avatar philidem commented on May 18, 2024

@ariporad I'm almost certain that the line require('app-module-path').addPath(__dirname); still needs to be in the entry point of your NodeJS application due to how the app-module-path module hooks into the module loader.

If I have multiple entry points then add that line to each entry point file. For example if your application can be ran via node server.js and node build.js then add that line to server.js and build.js.

If you know of a way to modify app-module-path so that it can add a search path directory while in a non-entry point file then please let us know. Otherwise, I think we can close this issue with the answer that putting require('app-module-path').addPath(__dirname); in setup.js in your example will not work. You will need to add that line to index.js.

from app-module-path-node.

ariporad avatar ariporad commented on May 18, 2024

I'm working on a test for it, I'll let you know tomorrow morning.

Thanks!Ari

On Mon, Sep 7, 2015 at 7:58 PM, Phillip Gates-Idem
[email protected] wrote:

@ariporad I'm almost certain that the line require('app-module-path').addPath(__dirname); still needs to be in the entry point of your NodeJS application due to how the app-module-path module hooks into the module loader.
If I have multiple entry points then add that line to each entry point file. For example if your application can be ran via node server.js and node build.js then add that line to server.js and build.js.

If you know of a way to modify app-module-path so that it can add a search path directory while in a non-entry point file then please let us know. Otherwise, I think we can close this issue with the answer that putting require('app-module-path').addPath(__dirname); in setup.js in your example will not work. You will need to add that line to index.js.

Reply to this email directly or view it on GitHub:
#6 (comment)

from app-module-path-node.

ariporad avatar ariporad commented on May 18, 2024

I just tested it, it appears to work. You can see the results here: https://github.com/ariporad/test-app-module-path-in-setup-file

from app-module-path-node.

philidem avatar philidem commented on May 18, 2024

@ariporad maybe I'm missing something but your test project doesn't have a setup.js file. The line that uses app-module-path is in src/index.js which I assume is the entry point. Is this what you intended for your test?

from app-module-path-node.

patrick-steele-idem avatar patrick-steele-idem commented on May 18, 2024

I would actually expect it to work since app-module-path walks up the require tree to update the paths for already loaded parent modules using the following code:

while(parent && parent !== require.main) {
addPathHelper(parent.paths);
parent = parent.parent;
}

That was a later code change, but it is something that is supported. So to answer your question: Yes, it can be in a setup.js file.

I'm going to go ahead and close this issue, but feel free to comment or open another issue if you have other questions or concerns. Thanks.

from app-module-path-node.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.