ruby-on-rails 由于npm/pyton问题,rails部署在资产预编译时失败

l7mqbcuq  于 2023-04-13  发布在  Ruby
关注(0)|答案(1)|浏览(138)

在部署到Ubuntu 20.04服务器的过程中

01 $HOME/.rbenv/bin/rbenv exec bundle exec rake assets:precompile
      01 yarn install v1.22.19
      01 [1/4] Resolving packages...
      01 [2/4] Fetching packages...
      01 [3/4] Linking dependencies...
      01 warning " > webpack-dev-server@3.11.2" has unmet peer dependency "webpack@^4.0.0 || ^5.0.0".
      01 warning "webpack-dev-server > webpack-dev-middleware@3.7.3" has unmet peer dependency "webpack@^4.0.0 || ^5.0.0".
      01 [4/4] Building fresh packages...
      01 error /home/deploy/mainapp/releases/20230403051422/node_modules/node-sass: Command failed.
[...]
      01 gyp verb clean removing "build" directory
      01 gyp verb command configure []
      01 gyp verb check python checking for Python executable "python2" in the PATH
      01 gyp verb `which` failed Error: not found: python2
      01 gyp verb `which` failed     at getNotFoundError (/home/deploy/mainapp/shared/node_modules/which/which.js:13:12)
...
      01 gyp verb check python checking for Python executable "python" in the PATH
      01 gyp verb `which` failed Error: not found: python
      01 gyp verb `which` failed     at getNotFoundError (/home/deploy/mainapp/shared/node_modules/which/which.js:13:12)
[...]
     01 gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.
      01 gyp ERR! stack     at PythonFinder.failNoPython (/home/deploy/mainapp/shared/node_modules/node-gyp/lib/configure.js:484:19)
[... concluding with]
    01 gyp ERR! command "/usr/bin/node" "/home/deploy/mainapp/shared/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
      01 gyp ERR! cwd /home/deploy/mainapp/shared/node_modules/node-sass
      01 gyp ERR! node -v v18.15.0
      01 gyp ERR! node-gyp -v v3.8.0
      01 gyp ERR! not ok

调查:/usr/bin有两个目录python3python3.8。然而,部署似乎在寻找pythonpython2 ...
在另一台机器上部署相同的应用程序时没有发生这种情况,仍然是Ubuntu 20.04。
npm,python和webpack的复杂性令人困惑。
要完成资产预编译需要做什么?

relj7zay

relj7zay1#

根据@Alex的评论,node-gyp 3.8.0是违规方。为什么?
为什么使用Yarn工具

yarn why node-gyp
yarn why node-sass

允许一个人爬上依赖结构。在这个例子中,@rails#webpacker需要这些元素。
一路上,为了一个人的快乐、方便和强迫学习,铺设了许多香蕉皮:
·预先设置的rails应用程序可能会有gem版本转换。它可能是旧的。
·该gem实际上可能与package.json设置的内容不同步。
·即使这样,更新gem也不会渗透到Yarn生态系统
·用户可以随后在源机器上运行yarn install并尝试部署,开发成功的几率很大。
奇怪的是,开发和生产将
不**有相同的行为,至少在CSS方面(
我真的从来没有理解过为什么CSS必须像JS一样处理-就好像它们是由同一个人构思的 *)
·香蕉上的最后一颗樱桃:即使可以在最新版本的生产服务器上成功执行yarn installRAILS_EN=production bundle exec rake assets:precompile,生产服务器仍然无法部署
·需要先前的迭代(yarn安装和资产预编译中的一个或两个)以最终允许成功的生产部署。

相关问题