morjs icon indicating copy to clipboard operation
morjs copied to clipboard

Cannot read properties of undefined (reading 'ALIPAY')

Open saberfr opened this issue 2 years ago • 2 comments

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') image 3、关闭processNodeModules则恢复正常

saberfr avatar Sep 08 '23 05:09 saberfr

看了下编译后的文件,发现在定义ENV_TYPE之前前多了一行代码调用了@morjs/api,注释掉相关代码就正常了 image

saberfr avatar Sep 08 '23 06:09 saberfr

试了下,将注入配置里的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下有什么差异,希望官方能给个说明

saberfr avatar Sep 08 '23 08:09 saberfr