最近把打卡团服务器从Rails6升级到了Rails 7。其中一个改动是,将webpacker改成esbuild。改动本身其实并不难,将jsbunding-rails
和 cssbundling-rails
两个gem加到Gemfile里面。
然后执行各自的install task,照着网上的一些教程基本上就能搞定,这里不作详细的赘述。
在这个过程中,因为某个依赖不支持Node 15,于是升级到了node 16。但是在部署的时候,遇到一个问题,报了一个错:
In file included from /home/username/.cache/node-gyp/16.13.2/include/node/v8.h:30:0,
from /home/username/.cache/node-gyp/16.13.2/include/node/node.h:63,
from ../../nan/nan.h:58,
from ../src/binding.cpp:1:
/home/username/.cache/node-gyp/16.13.2/include/node/v8-internal.h: In function ‘void v8::internal::PerformCastCheck(T*)’:
/home/username/.cache/node-gyp/16.13.2/include/node/v8-internal.h:492:38: error: ‘remove_cv_t’ is not a member of ‘std’
!std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);
^~~~~~~~~~~
/home/username/.cache/node-gyp/16.13.2/include/node/v8-internal.h:492:38: note: suggested alternative: ‘remove_cv’
!std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);
^~~~~~~~~~~
remove_cv
/home/username/.cache/node-gyp/16.13.2/include/node/v8-internal.h:492:38: error: ‘remove_cv_t’ is not a member of ‘std’
/home/username/.cache/node-gyp/16.13.2/include/node/v8-internal.h:492:38: note: suggested alternative: ‘remove_cv’
!std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);
^~~~~~~~~~~
remove_cv
/home/username/.cache/node-gyp/16.13.2/include/node/v8-internal.h:492:50: error: template argument 2 is invalid
!std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);
^
/home/username/.cache/node-gyp/16.13.2/include/node/v8-internal.h:492:63: error: ‘::Perform’ has not been declared
!std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);
^~~~~~~
/home/username/.cache/node-gyp/16.13.2/include/node/v8-internal.h:492:63: note: suggested alternative: ‘herror’
!std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);
^~~~~~~
herror
binding.target.mk:133: recipe for target 'Release/obj.target/binding/src/binding.o' failed
make: *** [Release/obj.target/binding/src/binding.o] Error 1
make: Leaving directory '/var/www/theapp/shared/node_modules/node-sass/build'
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/var/www/theapp/shared/node_modules/node-gyp/lib/build.js:194:23)
gyp ERR! stack at ChildProcess.emit (node:events:390:28)
gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12)
gyp ERR! System Linux 4.15.0-72-generic
gyp ERR! command "/usr/bin/node" "/var/www/theapp/shared/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd /var/www/theapp/shared/node_modules/node-sass
gyp ERR! node -v v16.13.2
gyp ERR! node-gyp -v v7.1.2
gyp ERR! not ok
Build failed with error code: 1
rake aborted!
cssbundling-rails: Command css:build failed, ensure yarn is installed and `yarn build:css` runs without errors
/var/www/theapp/shared/bundle/ruby/2.7.0/gems/cssbundling-rails-1.0.0/lib/tasks/cssbundling/build.rake:5:in `block (2 levels) in <main>'
/var/www/theapp/shared/bundle/ruby/2.7.0/gems/rake-13.0.6/exe/rake:27:in `<top (required)>'
/var/www/theapp/shared/bundle/ruby/2.7.0/bin/ruby_executable_hooks:22:in `eval'
/var/www/theapp/shared/bundle/ruby/2.7.0/bin/ruby_executable_hooks:22:in `<main>'
Tasks: TOP => assets:precompile => css:build
(See full trace by running task with --trace)
可以看到,很明显的两行错误:
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/var/www/theapp/shared/node_modules/node-gyp/lib/build.js:194:23)
于是,我在google这行错误日志。搜出来一大堆答案,结果都不管用,大多数人搜出来的结果,都是各种原因引起的。跟我这边导致这个错误的原因不一样。周末试了好几次,还是同样没有结果。
今天回到家以后,心想应该找下根本原因再google,于是把错误日志又仔细看了下,往上可以看到这么一行:
/home/username/.cache/node-gyp/16.13.2/include/node/v8-internal.h:492:38: error: ‘remove_cv_t’ is not a member of ‘std’
把核心的 error: ‘remove_cv_t’ is not a member of ‘std’
一搜,结果瞬间就出来解决办法。
这里的核心是说,找到问题的root cause,google root cause的错误信息,能够更加准确的找到问题的答案。
所以,我愿称编程为:The Art of Reading Error Messages。