Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read properties of undefined (reading 'ALIPAY') #112

Open
saberfr opened this issue Sep 8, 2023 · 2 comments
Open

Cannot read properties of undefined (reading 'ALIPAY') #112

saberfr opened this issue Sep 8, 2023 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@saberfr
Copy link

saberfr commented Sep 8, 2023

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
Copy link
Author

saberfr commented Sep 8, 2023

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

@saberfr
Copy link
Author

saberfr commented Sep 8, 2023

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

@hwaphon hwaphon added the bug Something isn't working label Sep 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants