Giter Site home page Giter Site logo

Comments (11)

palavrov avatar palavrov commented on July 29, 2024 1

Version 2.0 still depends from electron and fails with browserify/nexe bundling.

Note that nexe is using browserify for the server and not for the browser so the provided shim doesn't help at all. It is kind of electron but without the webkit - just packaging everything in one executable.

Probably the same problem will be for nw.js or other node compatible bundlings.

I.e. until app-root-path depends on __dirname the problem with nexe will remain.

from node-app-root-path.

ctrlplusb avatar ctrlplusb commented on July 29, 2024

Same issue applies with the latest version, substitute remote for electron.

from node-app-root-path.

palavrov avatar palavrov commented on July 29, 2024

My final solution was to remove app-root-path - because actually it doesn't work properly after browserify (in my case this is side effect of using nexe).

The problem was that __dirname holds its value as it was during the compilation even when you move the app to somewhere else.

The only thing that I need was to get where the app directory is so my workaround was this:

var path = require("path");

var isNode = path.basename(process.argv[0]).toLowerCase().startsWith("node");
var rootPath = path.dirname(process.argv[ isNode ? 1 : 0]);

May be this will solve your problem too or may be it can be added to app-root-path instead using of complicated logic and dependency to third party packages.

from node-app-root-path.

inxilpro avatar inxilpro commented on July 29, 2024

I'm working on a release that will publish an alternate browser script that is just a shim. That should mean that you can use it inside a browser app and ir at least won't break things.

from node-app-root-path.

inxilpro avatar inxilpro commented on July 29, 2024

Take a look at version 2.0 — does that fix your issues with browserify?

from node-app-root-path.

inxilpro avatar inxilpro commented on July 29, 2024

I see. The most recent change should help with browserify, but not nexe. I'll dig around a bit and see if I can find a solution there. I also don't love the electron-specific code. I'm going to see what I can do there, too.

from node-app-root-path.

palavrov avatar palavrov commented on July 29, 2024

I was thinking about that too and think that conceptually we are looking for different things depend the app:

  • the directory where the app resides
  • the app node_modules directory which can be:
    • a subdirectory of the previous one
    • completely missing in case of bundling
    • something in between - some modules are bundled, some are in the subdirectory
  • platform agnostic system wide or per user app directory to keep data assets

Initially I was trying to use app-root-path to get the app directory to keep system wide data in it. Then I replace it with this monkey workaround but still I'm not happy how it is solved. May be we will need completely new module to provide all these directories or to add more logic to app-root-path to support that. Just my 2 cents ...

from node-app-root-path.

inxilpro avatar inxilpro commented on July 29, 2024

Can you give me a little more detail about how you're using it with nexe? My understanding is that nexe just packages the whole app into a single file, and doesn't support dynamic require() statements, so a tool like this would never work with it.

from node-app-root-path.

inxilpro avatar inxilpro commented on July 29, 2024

I ended up refactoring the electron logic a tiny bit, and while I did that, I also made the require statement for electron dynamic, which should help address this issue.

from node-app-root-path.

inxilpro avatar inxilpro commented on July 29, 2024

(See release 2.0.1)

from node-app-root-path.

palavrov avatar palavrov commented on July 29, 2024

Yep, nexe is doing exactly that but first it packs everything with browserify. Then in run time someone (nexe or browserify) emulates __dirname passing the compile time directory i.e. the directory where the sources were during the bundling step i.e. all logic based on __dirname will fail.

My usage of app-root-path & nexe was trivial - app-root-path was dependency and was used to create directory relative to the app path. At one moment I realize that wherever I move the build executable file it was not creating this directory at expected place but was going all the time to the compile time directory. IMHO this behavior will be the same with all such packers and bundlers because they don't know what to do with __dirname, how to emulate it. May be the best will be if they just fail when __dirname is used to avoid unpredictable or weird results.

from node-app-root-path.

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.