我正在尝试将require()
设置为动态路径myPath
:
let myPath = './myDynamicModule';
require( { myPath } )
但我仍然收到错误消息:
error: bundling failed: myComponent.js: myComponent.js:Invalid call at line 9: require({
myPath: myPath
})
我做错了什么?
谢谢大家。
UPDATE
import React, { Component } from 'react';
const ComponentIndex = ({ myModule }) => {
const myPath = '../modules/' + myModule;
RevRetComponent = require(revPath).default;
return <RevRetComponent />;
}
export default ComponentIndex;
尝试以这种方式导入路径
const path = '../imports/modules/core/startup/client';
import path;