收藏
回答

app.绑定require,page里app.require引入失败?

Windows 10 专业版20H2 ,微信开发者工具Stable1.05.2201240 , 调试库2.22.0

在App绑定require,Page里获取app,直接app.require引入报错



设置路径path变量为'.utils/util'时 会报错 Error:module "utils/util.js"is not defined

将路径写死为'.utils/util'时 代码运行正常

//util.js
module.exports = {
  testFunc(value) {
    return `testFunc${value}`;
  },
};
//app.js
App({
  onLaunchfunction () {},
  require(path) {
    return require(`${path}`);
    //return require("./utils/util");
  },
});
//demo.js
const { testFunc } = getApp().require("./utils/util");
Page({
  onLoad() {
    const str = testFunc(1);
    console.log(str);
    this.setData({
      str,
    });
  },
});
最后一次编辑于  2022-01-27
回答关注问题邀请回答
收藏

11 个回答

  • 富贵
    富贵
    2022-03-04

    在线等~~,昨天还可以,今天就不可以了

    2022-03-04
    有用
    回复 1
    • Cailven
      Cailven
      2022-03-11
      不升级是好的,开发工具的问题,工具回滚回去就好了
      2022-03-11
      1
      回复

正在加载...

登录 后发表内容