Thursday, October 28, 2021

[SOLVED] Can't run 'expo start' on a expo-react-native app, permission problem

Issue

Well, i see that already have many questions related to my problem on this site, but i also see that NONE of the solutions work for my specific case, because of that, i am opening that question, so it is not a duplicate.

Context (environment)

  • Linux Mint 19.1 Cinnamon
  • Expo v32
  • React-Native-Application
  • GitHub Private Repository (from where i cloned the app)
  • Node Latest LTS (v10.15.1)
  • NPM v6.4.1
  • /\ Both using NVM (Node Version Manager)

package.json

{
"main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "eject": "expo eject"
  },
  "dependencies": {
    "@expo/vector-icons": "^9.0.0",
    "expo": "^32.0.0",
    "lodash.clonedeep": "^4.5.0",
    "native-base": "^2.10.0",
    "react": "16.5.0",
    "react-native": "https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz",
    "react-native-credit-card-input": "https://github.com/itspauloroberto/react-native-credit-card-input.git",
    "react-native-password-strength-meter": "https://github.com/itspauloroberto/react-native-password-strength-meter.git",
    "react-native-responsive-screen": "^1.2.0",
    "react-native-scalable-image": "^0.5.0",
    "react-navigation": "^3.0.9",
    "react-redux": "^6.0.0",
    "redux": "^4.0.1",
    "redux-form": "^8.1.0",
    "redux-saga": "^0.16.2",
    "url-join": "^4.0.0",
    "vanilla-masker": "^1.2.0"
  },
  "devDependencies": {
    "babel-preset-expo": "^5.0.0"
  },
  "private": true
}

The Problem

My problem is when i try to run the following command expo start or npm start that is the same.

I HARDLY BELIEVE THAT IS A OS PROBLEM because last week i was using the same project on another os elementary-os and i had not any problems!

Then i get this error when i execute expo start or npm start:

Uncaught Error { [Error: EACCES: permission denied, open '/home/itspauloroberto/.expo/state.json.354451305']
  errno: -13,
  code: 'EACCES',
  syscall: 'open',
  path: '/home/itspauloroberto/.expo/state.json.354451305' }

How to reproduce it:

  • Install/Use the OS Linux Mint 19.1 Cinnamon.
  • Install nvm (node-version-manager)
  • Install npm and node using nvm install 10.15.1
  • Install expo-cli using npm install expo-cli
  • Create a new expo react-native project using expo init.
  • Try to run it using expo start.

What i've tried

First of all, i have sure that this project/application runs ok, because i had another OS (elementaryOS) on last week and i was working on the project with no problems, also i have a team that works on it with no problems also.

  • I tried to reinstall my node and npm and also the expo-cli.
  • I tried to rm -rf node_modules and npm install.
  • I tried to remove the package.lock.json and npm install again.
  • I tried to set a global dir for npm global installs with permission as said here
  • I tried to install nvm node version manager, (and i am using it atm).
  • I tried to chown myuser project-folder to give my user access to the folder (tried on .expo folder and node_modules folder also)
  • I tried to chmod 777 and 755 and 655 the whole project folder.
  • I tried to run the expo start, npm start command with sudo prefix but sudo cannot find expo or neither npm.
  • I tried to remove the repository and clone it using git clone again.
  • And many, many, many other things. (also i did preys)
  • Also there is no SELinux involvement as you can see below:

    ls -ld

    drwxr-xr-x 2 itspauloroberto itspauloroberto 4096 Feb 20 14:54 .

Because of that i am creating this question, even if i see this error on many of the website none have my context.


Solution

I found the problem!

The main reason was because, in some moment, i used sudo to install something related to expo, then expo created some files that belongs to the root user in another directory that was not on the project folder that i am working.

So it was because the initial files by expo on the very initial install of expo was installed using sudo apparently, because the files inside this directory: home/itspauloroberto/.expo and also the folder was owned by root (i checked it using la -ls command and saw root as the owner.) instead of my user itspauloroberto that was the main source of the error.

To get rid of this error, do the following steps:

  • navigate to the home/your_user/ directory.
  • delete the .expo folder using sudo rm -rf .expo (sudo needed because the folder owner is root)
  • run again expo using expo start

If you find any additional errors related to some directory or file, navigate to the file/directory that is on the error message and delete it. Because it should belong to root user also.



Answered By - Paulo Roberto Rosa