这是JobInfoPage.js文件的摘录
import findMonthsTillSession from '../components/utility.js';
class JobInfoPage extends Component {
render() {
<div>The nearest hiring session is in: { findMonthsTillSession() } See you then!</div>
}
}
我收到此错误:
Attempted import error: '../components/utility.js' does not contain a default export (imported as 'findMonthsTillSession').
答案 0 :(得分:0)
您的问题有2个错误,
(1)No return() in JobInfoPage.js
文件
(2)Function is not imported with function name.
在JobInfoPage.js
import findMonthsTillSession from '../components/utility.js';
class JobInfoPage extends Component {
render() {
return(
<div>
The nearest hiring session is in: { findMonthsTillSession() } See you then!
</div>
)
}
}
如果尚未添加,请在Utility.js中添加import React from 'react';
。
答案 1 :(得分:0)
您需要将React导入您的Utility.js
import React from 'react';
export function FindMonthsTillSession() {
return <p> 5 months </p>;
}
然后按如下所示导入实用程序:
import FindMonthsTillSession from '../components/utility
答案 2 :(得分:0)
感谢大家的帮助!我猜因为自从我导出了默认的 ,所以我不得不在导入文件上放花括号,就像这样:
import { findMonthsTillSession } from '../components/utility.js';
现在是计算月份的难点!