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 > email@example.com: 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 > firstname.lastname@example.org: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies. warning nuxt > @nuxt/webpack > webpack > watchpack > watchpack-chokidar2 > chokidar > email@example.com: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2. [2/4] Fetching packages... info firstname.lastname@example.org: The platform "linux" is incompatible with this module. info "email@example.com" is an optional dependency and failed compatibility check. Excluding it from installation. info firstname.lastname@example.org: The platform "linux" is incompatible with this module. info "email@example.com" is an optional dependency and failed compatibility check. Excluding it from installation. [3/4] Linking dependencies... [4/4] Building fresh packages... success Installed "firstname.lastname@example.org" 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: