morjs
morjs copied to clipboard
Cannot read properties of undefined (reading 'ALIPAY')
1、processNodeModules设为true
import { defineConfig } from '@morjs/cli'
export default defineConfig([
{
name: 'web',
sourceType: 'wechat',
target: 'web',
compileType: 'miniprogram',
processNodeModules: true,
compileMode: 'bundle',
cache: false
}
])
2、执行npm run dev:web,编译没问题,打开页面报:
Cannot read properties of undefined (reading 'ALIPAY')
3、关闭processNodeModules则恢复正常
看了下编译后的文件,发现在定义ENV_TYPE之前前多了一行代码调用了@morjs/api,注释掉相关代码就正常了
试了下,将注入配置里的api改为lite,使用my对象来替代__MOR_API__能解决这个问题:
{
name: 'web',
sourceType: 'wechat',
target: 'web',
compileType: 'miniprogram',
processNodeModules: true,
compileMode: 'bundle',
autoInjectRuntime: {
app: true,
page: true,
component: true,
behavior: true,
// API 运行时抹平注入, 指定为 true 时默认为 `enhanced`, 可选值:
// enhanced: 增强方式: MorJS 接管 API 调用并提供接口兼容支持
// lite: 轻量级的方式: wx => my, 替换所有全局接口对象
// minimal: 最小替换, 如 wx.abc() => my.abc(), 仅替换函数调用
api: 'lite'
},
}
就是不清楚my和__MOR_API__在web下有什么差异,希望官方能给个说明