为什么每次从 github 拉取时都必须删除 node_modules 文件夹
Why must I delete the node_modules folder every time I pull from github
我知道这可能是一个简单的问题,但我很好奇为什么我每次从我的 github 存储库中提取时都必须删除 node_modules 文件夹。
当我尝试从我的存储库中提取后执行“npm start”时,我收到以下错误,并且在删除 node_modules 文件夹并执行“npm install”后,问题暂时得到解决。
sh: react-scripts: command not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT...
我注意到该文件夹显示为推送时所做更改的一部分(大约 2,800 个文件)。
在这种情况下,我需要忽略 node_modules 文件夹 (.gitignore) 以阻止这种情况发生吗?
关于为什么会发生这种情况的任何解释也很酷,就像对我来说仅供参考。
非常感谢您。
您应该将 node_modules 目录添加到 .gitignore 中,以免被推送到存储库中,然后将其删除。
而node_modules应该只在你的开发环境中生成。
创建一个名为 .gitignore
的文件并将以下代码粘贴到其中(PS:您可以在所有项目中使用此文件,它包含几乎所有您必须忽略的扩展名和文件夹将项目推送到 github 时):
# Numerous always-ignore extensions
*.diff
*.err
*.orig
*.log
*.rej
*.swo
*.swp
*.vi
*~
*.sass-cache
node_modules/
.tmp/
.vs
# OS or Editor folders
.DS_Store
Thumbs.db
.cache
.project
.settings
.tmproj
*.esproj
nbproject
*.sublime-project
*.sublime-workspace
*.komodoproject
.komodotools
_notes
dwsync.xml
.sass-cache
.idea
我知道这可能是一个简单的问题,但我很好奇为什么我每次从我的 github 存储库中提取时都必须删除 node_modules 文件夹。 当我尝试从我的存储库中提取后执行“npm start”时,我收到以下错误,并且在删除 node_modules 文件夹并执行“npm install”后,问题暂时得到解决。
sh: react-scripts: command not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT...
我注意到该文件夹显示为推送时所做更改的一部分(大约 2,800 个文件)。 在这种情况下,我需要忽略 node_modules 文件夹 (.gitignore) 以阻止这种情况发生吗? 关于为什么会发生这种情况的任何解释也很酷,就像对我来说仅供参考。
非常感谢您。
您应该将 node_modules 目录添加到 .gitignore 中,以免被推送到存储库中,然后将其删除。 而node_modules应该只在你的开发环境中生成。
创建一个名为 .gitignore
的文件并将以下代码粘贴到其中(PS:您可以在所有项目中使用此文件,它包含几乎所有您必须忽略的扩展名和文件夹将项目推送到 github 时):
# Numerous always-ignore extensions
*.diff
*.err
*.orig
*.log
*.rej
*.swo
*.swp
*.vi
*~
*.sass-cache
node_modules/
.tmp/
.vs
# OS or Editor folders
.DS_Store
Thumbs.db
.cache
.project
.settings
.tmproj
*.esproj
nbproject
*.sublime-project
*.sublime-workspace
*.komodoproject
.komodotools
_notes
dwsync.xml
.sass-cache
.idea