简体   繁体   中英

MongoDB Atlas and axios in Functions throws error

Trying to use axios in my MongoDB Atlas under Functions . Dependency axios was added successfully.

However following function throws axios error:

exports = function() {
  const axios = require("axios");
axios.get('https://api.github.com/users/PowellTravis/repos?per_page=100&page=1')
  .then(function (response) {
    onSuccess(response)
  })
  .catch(function (error) {
    console.log(error);
  });
}

and this is the error:


failed to execute source for 'node_modules/axios/index.js': FunctionError: failed to execute source for 'node_modules/axios/lib/axios.js': FunctionError: failed to execute source for 'node_modules/axios/lib/core/Axios.js': FunctionError: failed to execute source for 'node_modules/axios/lib/core/dispatchRequest.js': FunctionError: failed to execute source for 'node_modules/axios/lib/adapters/adapters.js': FunctionError: failed to execute source for 'node_modules/axios/lib/adapters/http.js': TypeError: Cannot access member 'Z_SYNC_FLUSH' of undefined
    at node_modules/axios/lib/adapters/http.js:36:10(187)

    at require (native)
    at node_modules/axios/lib/adapters/adapters.js:16:44(41)

    at require (native)
    at node_modules/axios/lib/core/dispatchRequest.js:20:48(77)

    at require (native)
    at node_modules/axios/lib/core/Axios.js:18:55(63)

    at require (native)
    at node_modules/axios/lib/axios.js:17:45(51)

    at require (native)
    at node_modules/axios/index.js:22:45(73)

Anyone has a clue?

Please update the "axios" package with any specific version <= 1.2.0. Somehow atlas trigger functions are not supporting "axios" versions > 1.2.1. I hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM