部署到 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 " > [email protected]" has unmet peer dependency "webpack@^4.0.0 || ^5.0.0".
01 warning "webpack-dev-server > [email protected]" 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 版本。它可能是旧的。
• 事实上,该宝石可能与
package.json
设置的内容不同步。yarn install
并尝试部署。很有可能开发会成功。• 奇怪的是,开发和生产将
yarn install
或
RAILS_EN=production bundle exec rake assets:precompile
• 需要先前的迭代(纱线安装和资产预编译之一或两者)才能最终实现成功的生产部署。