Zapier自定义认证测试报错:需传入函数/数组/对象却获undefined
Zapier自定义认证测试报错:
You must pass in a function/array/object. We got undefined instead. 排查方案 1. 核对模块导出与导入逻辑
- 先确认
authentication.js里test函数的导出方式:
如果是默认导出(export default test),那index.js里得把它挂载到authentication.test,示例代码:
如果是命名导出(import authTest from './authentication'; export default { authentication: { test: authTest, // 其他认证相关配置(如type、fields等) } }export const test = () => {}),要在index.js里正确解构导入:import { test as authTest } from './authentication'; export default { authentication: { test: authTest, // 其他认证相关配置 } } - 务必保证
index.js完整导出了包含authentication.test字段的App对象,别漏写任何配置项。
2. 检查测试文件的App导入路径
- 确认
authentication.test.js里导入App的路径是对的,比如项目根目录下的测试文件应该写:
要是项目结构有嵌套层级,路径得对应调整,别因为路径错误导致App对象加载不完整。import App from '../index';
3. 验证Zapier CLI版本
- 运行
zapier --version查看当前CLI版本,要是版本太老,可能存在模块解析的兼容性问题。执行npm install -g zapier-platform-cli升级到最新稳定版,再重新跑测试。
4. 检查test函数的合法性
- 确保
authentication.js里的test是符合Zapier要求的异步函数,必须接收z和bundle两个参数,示例:
函数得返回Promise(或用async/await语法),不能是普通同步函数或者定义有误的结构。export const test = async (z, bundle) => { const response = await z.request({ method: 'GET', url: 'https://你的API认证测试端点' }); if (response.status !== 200) { throw new Error('认证失败'); } return { success: true }; };
5. 清理缓存重新构建
- 删除项目里的
node_modules文件夹和package-lock.json文件,重新执行npm install,再运行zapier build,之后再跑测试。缓存问题偶尔会导致模块加载异常,清缓存能解决这类问题。
内容的提问来源于stack exchange,提问作者Ethandev
相关产品推荐
相关产品推荐

