
Halo, kalau kamu merasa tulisan saya ngebantu kamu, kamu bisa ucapkan terima kasih lewat saweria .
If you feel this website help you, you can donate at saweria .
Tips, Tricks, & Beberapa Permasalahan React JS di Production
-
Deploy di production tanpa
npm run build
(langsungnpm start
)Hasil npm run build Lebih Optimal
Berdasarkan dokumentasi resmi , memang disarankan menggunakan
npm run build
lalu di serve menggunakanserve -s build -p 3000
-
“Cannot find module xxx” saat
serve -s build -p 3000
.Cannot Find serve Module
Error ini biasanya ada di aplikasi React JS yang pake docker.
Sudah include
serve
di package.json kenapa pas diserve
malah masih error juga? Sudah tambahinnpm install serve
juga masih error.Solusinya mudah, tambahkan node_modules PATH,
ENV PATH /app/node_modules/.bin:$PATH
. . . # here is my example Dockerfile RUN mkdir -p /app WORKDIR /app # dont forget add this line ENV PATH /app/node_modules/.bin:$PATH COPY package.json /app/package.json . . .
-
npm run build
lama banget jalannya.Ini memang lama ya, tunggu aja, jangan pernah gunakan
npm run start
di production! -
Serve React JS di production dengan PM2 .
Bikin file pm2-app.json, isi dengan
{ "apps" : [ { "name" : "aplikasi", "script" : "npx", "autorestart" : false, "interpreter" : "none", "args" : "serve -s build -p 3000", "ignore_watch": ["public", "test", "docs", "bin", "node_modules", ".github", "ckeditor5", "src", ".git"], } ] }
Jalankan dengan
pm2 start pm2-app.json
, sebelumnya tetap jangan lupa jalankannpm run build
-
Reserve, bakal di update terus!
Referensi: