Comments (11)
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.
Same issue applies with the latest version, substitute remote
for electron
.
from node-app-root-path.
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.
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.
Take a look at version 2.0 — does that fix your issues with browserify?
from node-app-root-path.
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.
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.
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.
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.
(See release 2.0.1)
from node-app-root-path.
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)
- node_modules isn't cool anymore, what to do HOT 12
- Webpack warning: Critical dependency: the request of a dependency is an expression HOT 4
- Support for yarn workspaces HOT 8
- npm package.json version != github repo version HOT 1
- Path resolution in npm linked modules report module and not root app path. HOT 6
- New version broke webpack build with TypeORM HOT 3
- Auto including index.js HOT 1
- PNPM support?
- Latest NPM release failed (3.0.0) HOT 1
- What constituted the bump in major version? HOT 1
- Incompatible with Browserify HOT 1
- Mistenken added issue HOT 1
- Issues
- Issues
- Androidapk merge HOT 1
- wrongful access
- Google Cloud Functions reports incorrect path HOT 3
- Need Yarn 2 monorepo support
- Package throws an error when imported in an ES module installed globally on Ubuntu HOT 1
- ReferenceError: __dirname is not defined in ES module scope HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-app-root-path.