Today, my objective is to deploy the frontend code to the VPS, allowing everyone to access and debug it, rather than working on it in isolation.
Initially, I utilized the rsync
command to transfer the code:
rsync -avz /Users/workmac/documents/work-web-nginx/PTE-Web-Source root@cowpte.com:/home/cowpte/public_html
However, upon attempting to start the program, I encountered an issue: bash: npm: command not found.
This arose due to the absence of node
and npm
on the VPS server running CentOS.
Following the installation of Node.js via yum install nodejs
, a new issue emerged – react-scripts not found
:
> pte@0.1.0 start
> react-scripts start
node:internal/modules/cjs/loader:1031
throw err;
^
Error: Cannot find module '/home/cowpte/public_html/PTE-Web-Source/node_modules/.bin/react-scripts'
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1028:15)
at Function.Module._load (node:internal/modules/cjs/loader:873:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:22:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
Despite attempts to rectify the issue by reinstalling node_modules, node, and npm, the problem persisted. I even attempted to use nvm
to install a specific Node.js version v20.6.1, but compatibility issues with CentOS 7 led to further frustration. I eventually installed nodejs v16, which is compatible.
react-scripts version mismatch
I began to contemplate whether the version of react-scripts in my project was higher than that supported by Node.js v16. To investigate further, I initiated a new project with create-react-app directly on the VPS server. Upon running npm start, the project launched successfully, hinting at a possible compatibility issue between the versions.
Unfortunately, even if npm start functioned properly, the application remained inaccessible.
Try npm run build rather than npm run
As a solution, I opted to try npm run build
. Success! I could execute npm run build on my local Mac computer. It’s essential to remember to include "homepage": "./"
to avoid a 404 error for manifest.json.
In conclusion, I managed to resolve the issue without downgrading my Mac’s Node.js version or upgrading the VPS OS (CentOS). This outcome translates to cost savings.