我正在尝试导入模块,但它一直在浏览器(Chrome和Mozilla)控制台中抛出错误
Uncaught Error: Cannot find module "../../helpers/oidcHelpers.jsx"
- LoginController.jsx?1471:6
这是我的LoginController.jsx文件
import React, {Component, PropTypes} from 'react';
import ActionAndroid from 'material-ui/svg-icons/action/android';
import RaisedButton from 'material-ui/RaisedButton';
import userManager from '../../helpers/oidcHelpers.jsx';
export default class LoginController extends Component {
onFASLoginButtonClick = (event) => {
event.preventDefault();
console.log(userManager.signinRedirect);
userManager.signinRedirect();
};
render() {
return (
<div>
<RaisedButton
label="Login with FAS"
icon={<ActionAndroid/>}
onMouseUp={this.onFASLoginButtonClick}
/>
</div>
);
}
}
这是我的应用程序的目录结构。我已经剪断了不需要的文件
app
├── actions
│ └── actions.jsx
├── containers
│ ├── login
│ │ └── LoginController.jsx
├── helpers
│ ├── oidcHelpers.jsx
│ └── oidcHelpers.jsx.sample
├── index.jsx
├── reducers
│ ├── authentication.jsx
│ └── index.jsx
├── routes.jsx
└── stylesheets
├── base
│ └── common.less
├── components
└── drawer.less
尝试了很多,但无法弄清楚问题。我甚至尝试删除import语句并将导入更改为import userManager from '../../helpers/oidcHelpers'
但我仍然遇到同样的错误。进行更改不会更新浏览器中的代码。
代码托管在Github上:https://github.com/waartaa/waartaa/tree/develop/waartaa/client
答案 0 :(得分:1)
您在helpers/oidcHelpers.jsx
中没有默认导出。
将LoginController.jsx
中的导入从import userManager
更改为import { signinRedirect }
并通过调用signinRedirect
而非userManager.signinRedirect
正确使用
import React, {Component, PropTypes} from 'react';
import ActionAndroid from 'material-ui/svg-icons/action/android';
import RaisedButton from 'material-ui/RaisedButton';
import { signinRedirect } from '../../helpers/oidcHelpers.jsx';
export default class LoginController extends Component {
onFASLoginButtonClick = (event) => {
event.preventDefault();
console.log(signinRedirect);
signinRedirect();
};
render() {
return (
<div>
<RaisedButton
label="Login with FAS"
icon={<ActionAndroid/>}
onMouseUp={this.onFASLoginButtonClick}
/>
</div>
);
}
}