sindresorhus / fix-path Goto Github PK
View Code? Open in Web Editor NEWFix the $PATH on macOS and Linux when run from a GUI app
License: MIT License
Fix the $PATH on macOS and Linux when run from a GUI app
License: MIT License
fix-path: v2.0.0
Electron: v1.1.1
Node: v6.2.0
System: Yosemite 10.10.5
code:
const fixPath = require('fix-path');
console.log('PATH before fix:');
console.log(process.env.PATH);
fixPath();
console.log('PATH after fix:');
console.log(process.env.PATH);
logs:
PATH before fix:
/usr/bin:/bin:/usr/sbin:/sbin
PATH after fix:
/usr/bin:/bin:/usr/sbin:/sbin
Hey hey,
I'm struggling with $PATH
issues too. fix-path
unfortunately didn't help me, because I'm running node
via nvm
which is not covered by fix-path
.
Would it maybe be a good idea to follow the way run-node
does it?
-> https://github.com/sindresorhus/run-node
I tried to import as it is in the readme and got an error.
import fixPath from 'fix-path';
^^^^^^
SyntaxError: Cannot use import statement outside a module
at internalCompileFunction (node:internal/vm:73:18)
at wrapSafe (node:internal/modules/cjs/loader:1185:20)
at Module._compile (node:internal/modules/cjs/loader:1227:27)
at Module._extensions..js (node:internal/modules/cjs/loader:1326:10)
at Module.load (node:internal/modules/cjs/loader:1126:32)
at Module._load (node:internal/modules/cjs/loader:967:12)
at c._load (node:electron/js2c/node_init:2:13672)
at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)
at ModuleJob.run (node:internal/modules/esm/module_job:194:25)
A JavaScript error occurred in the main process
Uncaught Exception:
/home/pablo/GitHub/electron-test/src/index.js:6
import fixPath from 'fix-path';
^^^^^^
SyntaxError: Cannot use import statement outside a module
at internalCompileFunction (node:internal/vm:73:18)
at wrapSafe (node:internal/modules/cjs/loader:1185:20)
at Module._compile (node:internal/modules/cjs/loader:1227:27)
at Module._extensions..js (node:internal/modules/cjs/loader:1326:10)
at Module.load (node:internal/modules/cjs/loader:1126:32)
at Module._load (node:internal/modules/cjs/loader:967:12)
at c._load (node:electron/js2c/node_init:2:13672)
at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)
at ModuleJob.run (node:internal/modules/esm/module_job:194:25)
Hi
This module has been great for our application - many thanks !
We've now got to build a Linux (Ubuntu) version and we're getting a similar path problem. I tried fix-path but it doesn't seem to work on Linux. Are there any plans to extend it out to Linux ?
Thanks
Ian
When using Fix-path with Electron and electron-packager, it breaks the ability for the user to quit the application from the dock after packaging. Right clicking the doc-icon and selecting "Quit" does nothing.
This is explained in better detail here: electron/electron#8687 . For a minimal application reproducing the problem, see electron/electron#8687 (comment)
> echo $PATH
/Library/Frameworks/Python.framework/Versions/3.4/bin:/Applications/Postgres.app/Contents/Versions/9.3/bin:/usr/local/heroku/bin:/usr/local/sbin:/Users/dave/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/deployd/bin:/usr/local/go/bin:/usr/local/MacGPG2/bin
Using Electron 0.30.2:
require('fix-path')()
var dialog = require('dialog')
dialog.showErrorBox("path", process.env.PATH)
It works fine on my Macbook Pro but fails to list all the paths on my Macbook Air (as shown above). They are both running Yosemite. I have also reproduced the same issue on a friends Macbook.
Any idea what could be going on here?
I am using this in my vscode-yo plugin and noticed something strange. I upgraded some dotfiles of today and since then, the plugin wasn't showing any generators anymore. After investigating this, ANSI color codes where added in front of the path.
console.log(process.env.PATH.split(path.delimiter));
//=> [ '/Users/sam/.nvm/versions/node/v4.2.1/bin', '/usr/local/bin', ...]
require('fix-path')();
console.log(process.env.PATH.split(path.delimiter));
//=> [ '\u001b(B\u001b[m/Users/sam/.nvm/versions/node/v4.2.1/bin', '/usr/local/bin', ...]
After some more investigation, it seems that these lines in my dot-files trigger this behaviour.
if [[ $COLORTERM = gnome-* && $TERM = xterm ]] && infocmp gnome-256color >/dev/null 2>&1; then
export TERM='gnome-256color';
elif infocmp xterm-256color >/dev/null 2>&1; then
export TERM='xterm-256color';
fi;
If I remove these lines, the ANSI code is not added.
A simple fix is strip-ansi
require('fix-path')();
console.log(stripAnsi(process.env.PATH).split(path.delimiter));
//=> [ '/Users/sam/.nvm/versions/node/v4.2.1/bin', '/usr/local/bin', ...]
But maybe, this should be fixed somewhere deeper in the chain. After digging into with fix-path
does, I came to this line 72 in shell-path/index.js
. This is the line that returns the path with the ANSI color codes.
I got unexpected token error in fix-path code.
This is the content of fix-path:
'use strict';
module.exports = () => {
const env = process.env;
if (process.platform === 'darwin') {
return env.SHELL || '/bin/bash';
}
if (process.platform === 'win32') {
return env.COMSPEC || 'cmd.exe';
}
return env.SHELL || '/bin/sh';
}();
When I removed last ()
, it didn't give invalid syntax error.
What could be wrong?
I installed nodejs via brew
$ node --version v5.10.1
WARNING in ./node_modules/shell-env/node_modules/cross-spawn/index.js 30:20-41
Module not found: Error: Can't resolve 'spawn-sync' in '/Volumes/Projects/record/app/node_modules/shell-env/node_modules/cross-spawn'
@ ./node_modules/shell-env/node_modules/execa/index.js 7:19-41
@ ./node_modules/shell-env/index.js 3:14-30
@ ./node_modules/shell-path/index.js 3:17-37
@ ./node_modules/fix-path/index.js 3:18-39
@ ./app/main.dev.js 6:0-31 33:2-9
I think it may be the same issue as sindresorhus/shell-env#12
Basically I execute childProcess.execFileSync(process.env.SHELL, ['-c', 'echo $PATH']).toString().trim()
and get a different value than when I am in the terminal and I execute /bin/zsh -c 'echo $PATH'
. Wondering if you had any idea as to why that might be?
Thanks.
Just an idea:
var exec = require("child_process").execSync;
var userShell = String(exec("/bin/sh -c 'echo $SHELL'")).trim();
process.env.PATH = String(exec(userShell +" -c 'echo $PATH'")).trim();
This should work at least with bash
and zsh
and possibly other shells that take a -c
argument.
fix-path: 4.0.0
electron: 13.2.3
@craco/craco: 6.2.0
Hello, any idea what i'm doing wrong? My app fails to compile after add this package as a dep.
[0] Failed to compile.
[0]
[0] ./node_modules/default-shell/index.js
[0] Module not found: Can't resolve 'node:os' in '[...]/node_modules/default-shell'
Any way to use this with require
instead of import
?
I tried using multiple variations of require('fix-path')
but it won't work.
I'm unable to use import statement outside a module as it breaks all of my require related pieces.
Thank you!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.