acviana / vercel-nextjs-blog

Personal blog built on Nextra
https://www.acviana.com
2 stars 0 forks source link

Fix build Error (bump node to version >= 18.0) #7

Closed acviana closed 1 year ago

acviana commented 1 year ago

I had a build fail because the version of node I was using is no longer supported. I bumped the version number in the Vercel settings menu and now I'm getting a new error

I suspect this is because in my Vercel build log I'm using v18.16.1 but locally I'm using v20.5.0

acviana commented 1 year ago

After reading this SO post I decided to use nvm as a Node version management tool. Specifically, I used this project which is a pure Fish shell implementation.

Seems to be working:

❯ fisher install jorgebucaran/nvm.fish
fisher install version 4.4.3
Fetching https://api.github.com/repos/jorgebucaran/nvm.fish/tarball/HEAD
Installing jorgebucaran/nvm.fish
           /Users/alexviana/.config/fish/functions/_nvm_index_update.fish
           /Users/alexviana/.config/fish/functions/_nvm_list.fish
           /Users/alexviana/.config/fish/functions/_nvm_version_activate.fish
           /Users/alexviana/.config/fish/functions/_nvm_version_deactivate.fish
           /Users/alexviana/.config/fish/functions/nvm.fish
           /Users/alexviana/.config/fish/conf.d/nvm.fish
           /Users/alexviana/.config/fish/completions/nvm.fish
Downloading the Node distribution index...
Installed 1 plugin/s

~/dev/vercel-nextjs-blog main                                              ⬢ 20.5.1
❯ nvm install v18.17.0
Installing Node v18.17.0 lts/hydrogen
Fetching https://nodejs.org/dist/v18.17.0/node-v18.17.0-darwin-x64.tar.gz
Now using Node v18.17.0 (npm 9.6.7) ~/.local/share/nvm/v18.17.0/bin/node

~/dev/vercel-nextjs-blog main                                          3s ⬢ 18.17.0
❯ node --version
v18.17.0

Note that is all probably related to Vercel dropping Node 16 support on August 15th. I was running Node v20 locally but I bet my dependencies are pinned to something old somewhere/how.

acviana commented 1 year ago

OK, I did need to bump the version number but actually the problem was that all my packages were way too old in my packages.json file.

Just like with Poetry and Python, can check if your npm packages are up-to-date like this:

❯ npm outdated
Package            Current  Wanted   Latest  Location                        Depended by
next                12.3.4  12.3.4  13.4.19  node_modules/next               vercel-nextjs-blog
nextra               2.1.0  2.11.1   2.11.1  node_modules/nextra             vercel-nextjs-blog
nextra-theme-blog    2.1.0  2.11.1   2.11.1  node_modules/nextra-theme-blog  vercel-nextjs-blog
react               17.0.2  17.0.2   18.2.0  node_modules/react              vercel-nextjs-blog
react-dom           17.0.2  17.0.2   18.2.0  node_modules/react-dom          vercel-nextjs-blog

I committed this as a Makefile rule called check-packages. Upgrading all these packages in this commit https://github.com/acviana/vercel-nextjs-blog/commit/7f4144af50e1c13f667435b56dbf14f87fd32f7c fixed the build error.