Talk about the pitfalls of small program cloud development


Talk about the pitfalls of small program cloud development

When writing code, it is inevitable to make some low-end mistakes. Here are some mistakes I have made, hoping to help other scholars.

Error examples

// index.js
const cloud = require('wx-server-sdk')
//It is here that the author makes a very simple mistake. I write "request promise" as request.promise '
const rp=require('request-promise')
exports.main = async (event, context) => {
  //The openid, appid and unionid obtained here are trusted. Note that unionid is returned only when it meets the unionid acquisition condition
  let { OPENID, APPID, UNIONID } = cloud.getWXContext()
//1. Determine the interface
// ?cid=476559&count=10&page=0&filter_rating=0&bkn=&r=0.1621205141834321
// cid=476559&count=10&page=0&filter_rating=0&bkn=&r=0.26457182970476323
//Anti climbing referer:
//2. With the help of the module, you want to specify the interface to send the network request to get permission and return it
var options = {
  uri: '',
  qs: {
  headers: {
  json: true // Automatically parses the JSON string in the response
let  result = await rp(options).then(res=>{
  return res
return result

Here I make a very simple mistake, I write the request promise ‘as request.promise ‘
const rp=require(‘request-promise’)


Here, I would like to share some experience of error checking, which may be helpful to you

After writing the cloud function, first right-click the cloud function directory and select "open local function debugging". In the local function debugging interface, select the function you will debug, and then check the "open local debugging" button on the right side of the screen. Then the corresponding results will pop up. The error interface and the successful interface are shown below.

Success example chart

The result on the display shows that the cloud function can be uploaded to the cloud function of the cloud development console through debugging
Right click the cloud function directory, select "upload and deploy: cloud installation dependencies (do not upload node modules)" or select "upload and deploy: all files", and then wait for about 5S to see the cloud function we just uploaded in the visualization background and cloud function list.

Failure example diagram

Carefully check the system feedback error information, and analyze the error information

In my example, we can find that such an error was reported in the error message

Cannot find modules ‘ request.promise ‘when you get here, you suddenly realize that it was your own writing error, then change it to request promise, and debug it again

Sample diagram of error report without installing related plug-ins

The reasons for this may be as follows:
1. Is NPM environment installed
How to configure NPM?
2. Whether the relevant plug-ins are installed correctly
How to install plug-ins in NPM?

If there are mistakes in Xiaosheng’s article, you are welcome to correct them. If you have any questions, please welcome to diss me, and I will try my best to answer them