在 React 中调用 class 的 Webpack "Not a function" 错误
Webpack "Not a function" error for calling a class in React
在 React 应用程序中,我尝试将一些业务逻辑封装在 class 中,称为身份验证。当我尝试在身份验证 class 上调用名为 configure 的方法时,出现以下错误:
TypeError:
WEBPACK_IMPORTED_MODULE_5__authentication_js.a.configure is not a function
在我的 React app.js 文件中,我将身份验证 class 导入为:
import Authentication from './authentication.js';
然后我尝试在我的构造函数中访问它,如下所示:
constructor(props) {
super(props);
Authentication.configure();
}
authentication.js的代码如下:
class Authentication {
constructor(props) {
console.log('inside constructor of Authentication class');
}
configure(){
//some setup logic, still fails if I comment it all out
}
}
export default Authentication;
我不确定如何解决这个问题。我知道我在 react 之前看到过类似的问题,其中内部方法没有针对它调用 bind 方法,但我不确定外部 public 方法是否需要 class如果需要,我不确定如何实施。任何 help/guidance 将不胜感激。
configure
是Authentication
class的一个实例方法。
要么制作 configure
static,要么导出 Authentication
.
的 实例
在 React 应用程序中,我尝试将一些业务逻辑封装在 class 中,称为身份验证。当我尝试在身份验证 class 上调用名为 configure 的方法时,出现以下错误:
TypeError: WEBPACK_IMPORTED_MODULE_5__authentication_js.a.configure is not a function
在我的 React app.js 文件中,我将身份验证 class 导入为:
import Authentication from './authentication.js';
然后我尝试在我的构造函数中访问它,如下所示:
constructor(props) {
super(props);
Authentication.configure();
}
authentication.js的代码如下:
class Authentication {
constructor(props) {
console.log('inside constructor of Authentication class');
}
configure(){
//some setup logic, still fails if I comment it all out
}
}
export default Authentication;
我不确定如何解决这个问题。我知道我在 react 之前看到过类似的问题,其中内部方法没有针对它调用 bind 方法,但我不确定外部 public 方法是否需要 class如果需要,我不确定如何实施。任何 help/guidance 将不胜感激。
configure
是Authentication
class的一个实例方法。
要么制作 configure
static,要么导出 Authentication
.