Giter VIP home page Giter VIP logo

Comments (9)

rubbishquan avatar rubbishquan commented on June 20, 2024 1

用process.cwd()替代__dirname试试

from miniprogram-simulate.

JuneAndGreen avatar JuneAndGreen commented on June 20, 2024

有两种可能性:
1、可能环境判断不正确,重新安装一下 miniprogram-simulate 试试?保证这个包和相关依赖都是最新版本
2、路径不是绝对路径,可以输出一下 path.join(__dirname, '../components/index') 看看?

from miniprogram-simulate.

JerryYuanJ avatar JerryYuanJ commented on June 20, 2024

@kami1983 你可以将

const id = simulate.load(path.join(__dirname, '../components/index'))
改成

const id = simulate.load(path.join(__dirname, '../components/index/index')) 试试

参考源码:

/**
 * 注册自定义组件
 */
function register(componentPath, tagName, cache) {
  if (typeof componentPath === 'object') {
    // 直接传入定义对象
    const definition = componentPath

    return jComponent.register(definition)
  }

  if (typeof componentPath !== 'string') {
    throw new Error('componentPath must be a string')
  }

  if (!tagName || typeof tagName !== 'string') {
    tagName = 'main' // 默认标签名
  }

  const oldLoad = nowLoad
  const component = nowLoad = {
    tagName,
    json: _.readJson(`${componentPath}.json`),
  }

  if (!component.json) {
    throw new Error(`invalid componentPath: ${componentPath}`)
  }

实际上是要能获取组件对应的json配置文件的。

from miniprogram-simulate.

kami1983 avatar kami1983 commented on June 20, 2024

已经解决,谢谢大家!

from miniprogram-simulate.

smilebuz avatar smilebuz commented on June 20, 2024

已经解决,谢谢大家!

您好 我想请问下是如何解决的 因为我也遇到了这个问题 谢谢

from miniprogram-simulate.

katoto avatar katoto commented on June 20, 2024

问题应该出在“usingComponents” ,里头如果路径有问题就会造成

from miniprogram-simulate.

arleyGuoLei avatar arleyGuoLei commented on June 20, 2024

怎么解决的?

from miniprogram-simulate.

fangxxiaoming avatar fangxxiaoming commented on June 20, 2024

小程序组件里usingComponents引用的是绝对路径的,运行时候也提示路径问题,invalid componentPath,现在是无法支持吗

from miniprogram-simulate.

yrmatou avatar yrmatou commented on June 20, 2024

配置 jest moduleNameMapper属性就可以了 https://jestjs.io/zh-Hans/docs/configuration#modulenamemapper-objectstring-string--arraystring

from miniprogram-simulate.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.