React正在Ubuntu中创建“只读”项目

时间:2019-07-16 20:47:08

标签: reactjs ubuntu create-react-app

当我尝试创建React应用程序时,该项目最终变成只读的。我是Ubuntu(18.04.1)的新手,在Windows中没有此问题。这是我运行的所有内容的列表:

sudo apt-get install curl
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt-get install -y nodejs
sudo apt-get install -y build-essential
sudo npm install npm@latest -g
sudo npm install -g create-react-app
sudo create-react-app my_project
cd my_project
npm start

该项目本身没有错误,并且在我的浏览器中运行也没有错误。当我查看项目文件夹或其内容时,它被标记为只读。我不确定为什么。

  • 节点-v-> v8.10.0
  • npm -v-> 6.10.0
  • create-react-app --version-> 3.0.1

  • + react@16.8.6

  • + react-scripts@3.0.1
  • + react-dom@16.8.6

我使用sudo执行create-react-app是因为遇到以下错误:

Unhandled rejection Error: EACCES: permission denied, open '/home/username/.npm/_cacache/index-v5/81/a0/bf45891088d28eb42006f1c1e8b852a99c068c882f3b3e4cd59395aed2b2'

我发现在创建应用程序目录后执行此操作,然后将权限切换为我的权限:

sudo chown -R username:username my_project

我假设有一种方法可以使该应用程序目录在授予我的用户名权限的情况下自动创建。 例如。 :

npm install --unsafe-perm=true --allow-root -g package_name 

我假设还有一些永久更改所有权的方法,因此我不需要每次都使用sudo + chown。

例如:  1.更改目录所有者:

ls -l
whoami
sudo chown youruser file.txt
ls -l

npm config get prefix 
clear
ls -la /usr/local/lib/node_modules
sudo chown -R youruser /usr/local/lib/node_modules
sudo chown -R youruser /usr/local/bin/
sudo chown -R youruser /usr/local/share/
  1. 更改目录前缀
mkdir npm-global 
cd npm-global
pwd --> /Users/youruser/npm-global

npm config set prefix /Users/youruser/npm-global

npm install -g jshint
vi ~/.profile 
--> add line then:
--> export PATH=/Users/youruser/npm-global/bin:$PATH
refresh with :
source ~/.profile

在考虑节点和反应时,我不确定什么是“适当的”。

0 个答案:

没有答案