开发者社区 问答 正文

关于require(变量)报错问题 <b> ?报错

path = '../testClass';
const mod = require(path); //报错 ERROR Error: Cannot find module "."

require('../testClass'); // 正确

这是为什么,如果需要传入变量,该怎么写?

展开
收起
爱吃鱼的程序员 2020-06-23 15:45:23 577 分享 版权
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    在python中经常有的,,,版本不对造成的

    2020-06-23 15:45:40
    赞同 展开评论
问答地址: