โดน Google API วางยา Uncaught TypeError: _.Rp is not a function

Pop Poonpipat
Jul 20, 2017 · 1 min read

อยู่ดีๆ ยังไม่ได้แก้ Code อะไรก้อเจอ Error —

apis.google.com/js/client:platform.js:18 Uncaught TypeError: _.Rp is not a function
at https://apis.google.com/_/scs/apps-static/_/js/k=oz.gapi.en.pl8YAQBmp-8.O/m…=1/ed=1/am=AQ/rs=AGLTcCMMYNdMnsItWxK9p4Z9SMxBsPc-nQ/cb=gapi.loaded_1:8:501
at https://apis.google.com/js/client:platform.js:15:156
at ob (https://apis.google.com/js/client:platform.js:18:173)
at pb (https://apis.google.com/js/client:platform.js:15:87)
at u (https://apis.google.com/js/client:platform.js:17:93)
at b (https://apis.google.com/js/client:platform.js:17:323)
at Array.G.(anonymous function) (https://apis.google.com/js/client:platform.js:17:427)
at Object.B.(anonymous function) [as loaded_1] (https://apis.google.com/js/client:platform.js:17:491)
at https://apis.google.com/_/scs/apps-static/_/js/k=oz.gapi.en.pl8YAQBmp-8.O/m…d=1/ed=1/am=AQ/rs=AGLTcCMMYNdMnsItWxK9p4Z9SMxBsPc-nQ/cb=gapi.loaded_1:1:15

โชคดีมากที่เจอคนเพิ่งมาตอบภายในไม่กี่วิที่ — https://stackoverflow.com/questions/45202721/google-platform-js-suddenly-throwing-rp-undefined-exception-decipte-no-change

สาเหตุ คือ ทาง Google เค้า Update — API ของเค้า โดยมี function ชื่อ Map ขึ้นมา ซึ่งซ้ำ กับ function ของเราที่ สร้างไว้ก่อนหน้า เหมือนกัน เราเป็นผู้ใช้ เลยต้องแก้ Code เราไปตามระเบียบ :(

วิธีแก้ :

  1. เปลี่ยนชื่อ function “Map” ใน javascript code ของเราไป เรื่องเป็น ชื่ออื่นซะจะได้ไม่ซ้ำกับของ Google
  2. (วิธีที่ดีที่สุด) กำหนด NameSpace ให้กับ function Map ของเราซะ วิธีทำก้อตามนี้เลย: https://javascriptweblog.wordpress.com/2010/12/07/namespacing-in-javascript/
)
Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade