Thoughts

Fixing Yarn Build Errors

Yarn: https://yarnpkg.com/
Nuxt.js: https://nuxtjs.org/
SPA: https://en.wikipedia.org/wiki/Single-page_application

A frustrating day trying to solve a simple Yarn error building a Vue SPA with Nuxt. Only a few posts exist online with this error and none of them have the solution. So here is how I resolved it.

Firstly, here was the error:

$ yarn build
yarn run v1.22.4
warning ../../package.json: No license field
$ nuxt build
/bin/sh: nuxt: command not found
error Command failed with exit code 127.

Firstly Yarn is supposed to get all the required packages when you run yarn install so it makes no sense to me that nuxt cannot be found. I was initially trying to solve this by adding nuxt to my PATH but that made no difference.

The solution was simple, yarn can handle this but you need to run this to install nuxt:

yarn global add nuxt

$ yarn global add nuxt
yarn global v1.22.4
warning ../../../package.json: No license field
[1/4] Resolving packages...
warning nuxt > @nuxt/webpack > @nuxt/babel-preset-app > core-js@2.6.11: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.
warning nuxt > @nuxt/webpack > webpack > watchpack > watchpack-chokidar2 > chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
warning nuxt > @nuxt/webpack > webpack > watchpack > watchpack-chokidar2 > chokidar > fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
[2/4] Fetching packages...
info fsevents@2.1.3: The platform "linux" is incompatible with this module.
info "fsevents@2.1.3" is an optional dependency and failed compatibility check. Excluding it from installation.
info fsevents@1.2.13: The platform "linux" is incompatible with this module.
info "fsevents@1.2.13" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Installed "nuxt@2.12.2" with binaries:
      - nuxt
Done in 19.87s.

Now I can build the Nuxt SPA using Yarn!

So in summary, for first builds, after you have installed Yarn and you’ve copied your SPA from your repository, to build the application run the following:

yarn global add nuxt 
yarn install
yarn build

I found the solution via this post:

https://stackoverflow.com/questions/51809041/error-no-build-files-found-please-run-nuxt-build-before-launching-nuxt-star

Leave a Reply

Your email address will not be published. Required fields are marked *