在部署到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
有两个目录python3
和python3.8
。然而,部署似乎在寻找python
或python2
…
相同的应用程序在另一台机器上的另一个部署中没有发生这种情况,仍然是Ubuntu 20.04。
npm, python和webpack的复杂性令人困惑。
需要做什么来完成资产预编译?
根据@Alex的评论,node-gyp 3.8.0
是违规方。为什么?
为什么使用纱线工具
yarn why node-gyp
yarn why node-sass
允许我们沿着依赖关系结构往上爬。在本例中,@rails#webpacker
需要这些元素。
在此过程中,许多香蕉皮被放置为一个人的乐趣,方便和强制学习:
•一个预先设置的rails应用程序可能有gem版本。它可能是旧的。
•该gem实际上可能与package.json
设置的内容不同步。
•即使这样,更新gem也不会渗透到纱线生态系统
•随后可以在原始机器上运行yarn install
&;尝试部署。发展成功的可能性很大。
•奇怪的是,开发和生产将不有相同的行为,至少在CSS方面(我真的不明白为什么CSS必须像JS一样处理-好像它们是由相同的思想构想出来的)
•香蕉上的最后一颗樱桃:即使可以在最新版本的生产服务器上成功地执行yarn install
或RAILS_EN=production bundle exec rake assets:precompile
,产品仍然无法部署。
•需要之前的迭代(yarn安装和资产预编译中的一个或两个)才能最终允许成功的生产部署。