atom / apm

Atom Package Manager
https://atom.io/packages
MIT License
1.27k stars 298 forks source link

apm installed under WSL doesn't work correctly: "/opt/atom/resources/app/apm/bin/node.exe: No such file or directory" #751

Open bonotake opened 7 years ago

bonotake commented 7 years ago

Prerequisites

Description

I have installed Atom under Ubuntu on Windows Subsystem for Linux (i.e. I installed it on WSL, not on Windows). But the commands apm doesn't work correctly so far. The first error occurred was: "/usr/bin/apm: line 46: /opt/atom/resources/app/apm/bin/node.exe: No such file or directory". I checked the code and reverted this commit so the error dissappeared.

Steps to Reproduce

  1. Open WSL (in my environment, Ubuntu) bash.
  2. Run sudo apt install atom.
  3. Download https://github.com/atom/atom/releases/download/v1.21.2/atom-amd64.deb.
  4. Run dpkg -i atom-amd64.deb.
  5. Run apm --version

Expected behavior: The version of apm should be appeared.

Actual behavior: The error below occurs:

/usr/bin/apm: line 46: /usr/share/atom/resources/app/apm/bin/node.exe: No such file or directory

Reproduces how often: 100%, every time.

Versions

$ atom --version
Atom    : 1.21.2
Electron: 1.6.15
Chrome  : 56.0.2924.87
Node    : 7.4.0

apm --version cannot be done, as I mentioned above.

Additional Information

I guess this commit is for following the WSL/Windows interoperability and running Windows' native Atom from WSL, but is it strange to install and use Atom on WSL side?

ghost commented 6 years ago

Any fix on this? I have the same issue today.

genshen commented 6 years ago

I installed atom in my Windows Subsystem for Linux Ubuntu 18.04, which have the same error.

To fix it, just remove the additions in this commit 10525a7bd6b3680d961f7db04e1eb8d7211afb63 as @bonotake mentioned:

$ cd /your/atom/installed/path 
$ vi  resources/app/apm/bin/apm  # if you install atom using apt-get install atom, it will be at: /usr/share/atom/resources/app/apm/bin/apm

My apm file changes (apm version: 1.19.0, atom version 1.27.2) : change1: replace node.exe with node at line 17. change2: comment line 56 to line 61.

Before:

# Detect node binary name
osName=`uname -s`
if [ "${osName:0:10}" == 'MINGW32_NT' ]; then
  nodeBin="node.exe"
elif [[ $(uname -r) == *-Microsoft ]]; then
  nodeBin="node.exe" 
else
  nodeBin="node"
fi
...

cliPath="$binDir/../lib/cli.js"
if [[ $(uname -r) == *-Microsoft ]]; then
  cliPath="$(echo $cliPath | sed 's/\/mnt\/\([a-z]*\)\(.*\)/\1:\2/')"
  cliPath="${cliPath////\\}"
else
  builtin cd "$initialCwd"
fi

After:

# Detect node binary name
osName=`uname -s`
if [ "${osName:0:10}" == 'MINGW32_NT' ]; then
  nodeBin="node.exe"
elif [[ $(uname -r) == *-Microsoft ]]; then
  nodeBin="node"  #change 1:  remove  ".exe"
else
  nodeBin="node"
fi
...

cliPath="$binDir/../lib/cli.js"
# change 2: comment below lines
#if [[ $(uname -r) == *-Microsoft ]]; then
#  cliPath="$(echo $cliPath | sed 's/\/mnt\/\([a-z]*\)\(.*\)/\1:\2/')"
#  cliPath="${cliPath////\\}"
#else
builtin cd "$initialCwd"
#fi
realjkg commented 6 years ago

took me 2 hrs. to resolve this issue today - the fix worked for me under WSL w/ Ubuntu- Bionic Beaver- thx!!!

$ apm --version apm 1.19.0 npm 3.10.10 node 6.9.5 x64 atom 1.29.0 python 3.6.4 git 2.18.0

well done, @genshen!!

diveyez commented 5 years ago

Thank You. For people who want to conquer WSL, give me a shout because I have a full working xfce4 GUI and lots of other cool things actually working in it now.

freeman42x commented 5 years ago

I applied the changes to the file /usr/bin/apm:

#!/bin/bash

set -e

initialCwd=`pwd -P`
scriptDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

apmPath=$0
builtin cd "`dirname "$apmPath"`"
binDir=`basename "$apmPath"`

# Detect node binary name
osName=`uname -s`
if [ "${osName:0:10}" == 'MINGW32_NT' ]; then
  nodeBin="node.exe"
elif [[ $(uname -r) == *-Microsoft ]]; then
  nodeBin="node"  #change 1:  remove  ".exe"
else
  nodeBin="node"
fi

cliPath="$binDir/../lib/cli.js"
# change 2: comment below lines
#if [[ $(uname -r) == *-Microsoft ]]; then
#  cliPath="$(echo $cliPath | sed 's/\/mnt\/\([a-z]*\)\(.*\)/\1:\2/')"
#  cliPath="${cliPath////\\}"
#else
builtin cd "$initialCwd"
#fi

# Force npm to use its builtin node-gyp
unset npm_config_node_gyp

export ATOM_APM_ORIGINAL_PYTHON="${PYTHON:-}"

# Assumption: env iterates through environment variables in the same order that
# process.env iterates through properties within npm. So, we take the last match.
for var in $(env | grep -i ^npm_config_python=)
do
  ATOM_APM_ORIGINAL_PYTHON="${var#*=}"
  unset ${var%%=*}
done

export npm_config_python="${binDir}/python-interceptor.sh"

cliPath="$binDir/../lib/cli.js"
if [[ $(uname -r) == *-Microsoft ]]; then
  cliPath="$(echo $cliPath | sed 's/\/mnt\/\([a-z]*\)\(.*\)/\1:\2/')"
  cliPath="${cliPath////\\}"
else
  builtin cd "$initialCwd"
fi

"$binDir/$nodeBin" "$cliPath" "$@"

And I am getting the following error:

neo@DESKTOP-R88JKVQ:/mnt/c/WINDOWS/system32$ apm --version
/usr/bin/apm: line 55: apm/node: No such file or directory
vcmania commented 3 years ago

thank. my changed file.

#!/bin/bash

set -e

initialCwd=`pwd -P`
scriptDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

apmPath=$0
builtin cd "`dirname "$apmPath"`"
binDir=`basename "$apmPath"`

# Detect node binary name
osName=`uname -s`
if [ "${osName:0:10}" == 'MINGW32_NT' ]; then
  nodeBin="node.exe"
elif [[ $(uname -r) == *-Microsoft ]]; then
  if [ "${osName:0:5}" == 'Linux' ]; then
    nodeBin="node"
  else
    nodeBin="node.exe"
  fi
else
  nodeBin="node"
fi

while [ -L "$binDir" ]
do
  binDir=`readlink "$binDir"`
  builtin cd "`dirname "$binDir"`"
  binDir=`basename "$binDir"`
done

binDir=`pwd -P`

# Force npm to use its builtin node-gyp
unset npm_config_node_gyp

cliPath="$binDir/../lib/cli.js"
if [[ $(uname -r) == *-Microsoft ]]; then
  if [ "${osName:0:5}" == 'Linux' ]; then
    builtin cd "$initialCwd"
  else
    cliPath="$(echo $cliPath | sed 's/\/mnt\/\([a-z]*\)\(.*\)/\1:\2/')"
    cliPath="${cliPath////\\}"
  fi
else
  builtin cd "$initialCwd"
fi

"$binDir/$nodeBin" "$cliPath" "$@"