ellipsoid.js
/** * 椭球类对象 */class Ellipsoid { /** * 度转弧度 */ Radians(degrees) { return degrees * (Math.PI / 180) } /** * 弧度转度 */ Degrees(radians) { return radians * (180 / Math.PI) }} // 暴露模块接口,供外部调用module.exports = Ellipsoid |
index.js
// 云函数入口文件const Ellipsoid = require('./ellipsoid.js') // 云函数入口函数exports.main = async (event, context) => { var e = new Ellipsoid() return e.Degrees(event.data)} |
文档结构视图
问题:云函数中可以引用自定义JS模块吗?
const Ellipsoid = require('./ellipsoid.js')
此语句一直报错:error message Unexpected token =; at cloud.callFunction api;
求大神指教!

请问你解决了吗?
可以的
ellipsoid.js
/*** 椭球类对象*/class Ellipsoid {/*** 度转弧度*/static Radians(degrees) {returndegrees * (Math.PI / 180)}/*** 弧度转度*/static Degrees(radians) {returnradians * (180 / Math.PI)}}// 暴露模块接口,供外部调用// import { Ellipsoid } from '../../utils/ellipsoid.js'// var e = new Ellipsoid() // 实例化对象// e.IsChinese('测试') // 调用函数module.exports = Ellipsoidindex.js
// 云函数入口文件const Ellipsoid = require('./ellipsoid.js')// 云函数入口函数exports.main = async (event, context) => {vare =newEllipsoid()returne.Degrees(event.data)}帮看看哪儿有问题?
没看出问题 自己看看没有上传 环境有没有错 依赖有没有安装