微信云函数本地调试正常,线上测试失败检查方案

问题出处:

使用微信云函数上传文件时,用了wx.cloud.CDN(),需要在云函数中读取数据,其中使用了axios来发送请求,云函数中使用了

const axios = require("axios")

在package.json中添加了axios^1.1.2版本

错误提示:

Error: cloud.callFunction:fail Error: errCode: -504002 functions execute fail | errMsg: Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /var/user/node_modules/axios/index.js↵require() of ES modules is not supported.↵require() of /var/user/node_modules/axios/index.js from /var/user/index.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.↵Instead rename /var/user/node_modules/axios/index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /var/user/node_modules/axios/package.json.↵↵    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1174:13)↵    at Module.load (internal/modules/cjs/loader.js:1002:32)↵    at Function.Module._load (internal/modules/cjs/loader.js:901:14)↵    at Module.require (internal/modules/cjs/loader.js:1044:19)↵    at require (internal/modules/cjs/helpers.js:77:18)↵    at Object.<anonymous> (/var/user/index.js:3:15)↵    at Module._compile (internal/modules/cjs/loader.js:1158:30)↵    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)↵    at Module.load (internal/modules/cjs/loader.js:1002:32)↵    at Function.Module._load (internal/modules/cjs/loader.js:901:14) (callId: 1667377051899-0.7160831685344249) (trace: 16:17:31 start->16:17:32 system error (Error: errCode: -504002 functions execute fail | errMsg: Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /var/user/node_modules/axios/index.js↵require() of ES modules is not supported.↵require() of /var/user/node_modules/axios/index.js from /var/user/index.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.↵Instead rename /var/user/node_modules/axios/index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /var/user/node_modules/axios/package.json.↵↵    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1174:13)↵    at Module.load (internal/modules/cjs/loader.js:1002:32)↵    at Function.Module._load (internal/modules/cjs/loader.js:901:14)↵    at Module.require (internal/modules/cjs/loader.js:1044:19)↵    at require (internal/modules/cjs/helpers.js:77:18)↵    at Object.<anonymous> (/var/user/index.js:3:15)↵    at Module._compile (internal/modules/cjs/loader.js:1158:30)↵    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)↵    at Module.load (internal/modules/cjs/loader.js:1002:32)↵    at Function.Module._load (internal/modules/cjs/loader.js:901:14)), abort

 看了错误提示,得到结果,版本太新,不支持require,但是云函数环境不支持import,

降低版本号,解决问题

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

QIHU.ZY

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值