如何动态传递到InRequest Javascript的路径

如何动态传递到InRequest Javascript的路径,javascript,reactjs,react-native,require,Javascript,Reactjs,React Native,Require,我正在尝试使用动态路径设置require(): let myPath = './myDynamicModule'; require( { myPath } ) 但我一直在犯错误: error: bundling failed: myComponent.js: myComponent.js:Invalid call at line 9: require({ myPath: myPath }) 我做错了什么 提前谢谢大家 更新 import React, { Component } fr

我正在尝试使用动态路径设置
require()

let myPath = './myDynamicModule';
require( { myPath } )  
但我一直在犯错误:

error: bundling failed: myComponent.js: myComponent.js:Invalid call at line 9: require({
  myPath: myPath
})
我做错了什么

提前谢谢大家

更新

import React, { Component } from 'react';

const ComponentIndex = ({ myModule }) => {
    const myPath = '../modules/' + myModule;

    RevRetComponent = require(revPath).default;

    return <RevRetComponent />;
}

export default ComponentIndex;
import React,{Component}来自'React';
常量组件索引=({myModule})=>{
常量myPath='../modules/'+myModule;
RevRetComponent=require(revPath).default;
返回;
}
导出默认组件索引;

尝试以这种方式导入路径

const path = '../imports/modules/core/startup/client';
import path;

require
接受字符串作为参数,而不是对象,对吗?感谢您的回复@certainperformance
myPath
字符串的占位符,即
让myPath='./myDynamicModule'require
,而不是将其包装到对象中?该字符串在运行时动态定义。我在函数中接收它作为参数
require({myPath})
require(myPath)
会产生相同的错误。当然可以,所以尝试将该字符串传递给
require
,而不是将其包装在对象中?