部署失败,bin/yarn:权限被拒绝
Posted
技术标签:
【中文标题】部署失败,bin/yarn:权限被拒绝【英文标题】:Deployment failed, bin/yarn: Permission denied 【发布时间】:2021-07-27 22:24:51 【问题描述】:生产部署失败,好像是yarn没有权限读取文件。
部署时如何管理对纱线的权限?谢谢
Rails 6.1.3.1 // 节点 v15.5.1 // Tailwindcss: 2.1.1
生产日志
Using sassc-rails 2.1.2
Bundled gems are installed into `./vendor/bundle`
Running rake goals
Run rake assets:precompile
I, INFO -- : Writing /home/bas/app/public/assets/BlackswanLostintheswell4-600x320-0d7f660ace7096482a4523c9ffe8a9f8908628a6b07f84919a5a7c9bc4fd5693.jpg
I, INFO -- : Writing /home/bas/app/public/assets/surf-de-nuit-bc6077c7ea2f8e710dd8263b861b5919ef8f1a17c6124f4bb57d70a9c2d7296f.jpg
sh: line 1: /home/bas/app/bin/yarn: Permission denied
sh: line 1: /home/bas/app/bin/yarn: Permission denied
I, INFO -- : Writing /home/bas/app/public/assets/application-1a626ce625d708fd518476b336900a049f858135a41f621a0d478a2fe04c738a.css
I, INFO -- : Writing /home/bas/app/public/assets/manifest-b4bf6e57a53c2bdb55b8998cc94cd00883793c1c37c5e5aea3ef6749b4f6d92b.js
I, INFO -- : Writing /home/bas/app/public/assets/manifest-b4bf6e57a53c2bdb55b8998cc94cd00883793c1c37c5e5aea3ef6749b4f6d92b.js.gz
I, INFO -- : Writing /home/bas/app/public/assets/8J0A9786-1-600x330-f70182bc6c594c2f565eb91f855afc917598392be56e5167b6f97cab5e9d0214.jpg
I, INFO -- : Writing /home/bas/app/public/assets/8J0A9786-9f645e58550403181de9430ffc80e1a838a606e5114f9f8828768911806f7bff.jpg
I, INFO -- : Writing /home/bas/app/public/assets/application-1a626ce625d708fd518476b336900a049f858135a41f621a0d478a2fe04c738a.css.gz
I, INFO -- : Writing /home/bas/app/public/assets/pages-1a626ce625d708fd518476b336900a049f858135a41f621a0d478a2fe04c738a.css
I, INFO -- : Writing /home/bas/app/public/assets/pages-1a626ce625d708fd518476b336900a049f858135a41f621a0d478a2fe04c738a.css.gz
Compiling...
Compilation failed:
yarn run v1.22.10
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command "webpack" not found.
Build failed. Please check the logs above
Deploy failed
package.json
"name": "name",
"private": true,
"dependencies":
"@rails/actioncable": "^6.0.0",
"@rails/activestorage": "^6.0.0",
"@rails/ujs": "^6.0.0",
"@rails/webpacker": "rails/webpacker#b6c2180",
"@tailwindcss/aspect-ratio": "^0.2.0",
"@tailwindcss/forms": "^0.3.2",
"@tailwindcss/typography": "^0.4.0",
"autoprefixer": "^10.2.5",
"node": "^16.0.0",
"postcss": "^8.2.10",
"tailwindcss": "^2.1.1",
"tailwindcss-debug-screens": "^2.0.0",
"turbolinks": "^5.2.0"
,
"version": "0.1.0",
"devDependencies":
"webpack-dev-server": "^3.11.2"
bin/纱线
#!/usr/bin/env ruby
APP_ROOT = File.expand_path('..', __dir__)
Dir.chdir(APP_ROOT) do
yarn = ENV["PATH"].split(File::PATH_SEPARATOR).
select |dir| File.expand_path(dir) != __dir__ .
product(["yarn", "yarn.cmd", "yarn.ps1"]).
map |dir, file| File.expand_path(file, dir) .
find |file| File.executable?(file)
if yarn
exec yarn, *ARGV
else
$stderr.puts "Yarn executable was not detected in the system."
$stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
exit 1
end
end
https://github.com/yarnpkg/yarn/issues/1806 我授予了本地文件的权限,但不起作用
(本地)/bin
-rwxrwxrwx 1 root root 2945 Apr 15 12:09 bundle
-rwxrwxrwx 1 root root 141 Apr 15 12:09 rails
-rwxrwxrwx 1 root root 90 Apr 15 12:09 rake
-rwxrwxrwx 1 root root 1068 Apr 15 12:09 setup
-rwxrwxrwx 1 root root 414 Apr 15 12:09 webpack
-rwxrwxrwx 1 root root 419 Apr 15 12:09 webpack-dev-server
-rwxrwxrwx 1 root root 533 Apr 15 12:09 yarn
sh: 1: node: Permission denied 我试过了:
yarn config set user 0
yarn config set unsafe-perm true
【问题讨论】:
【参考方案1】:主要问题来自于在当前工作文件夹中安装纱线。
从文件夹中删除了纱线包:
sudo apt-get remove yarn && sudo apt-get purge yarn
并删除 /node_modules、yarn.lock 和 /bin/yarn
-
通过 webpacker 为 Npm 更改 Yarn:
https://dmitryshvetsov.com/how-to-use-webpacker-with-npm-instead-of-yarn-rails-guide/
部署
在根文件夹中安装纱线。
【讨论】:
以上是关于部署失败,bin/yarn:权限被拒绝的主要内容,如果未能解决你的问题,请参考以下文章