简体   繁体   English

“尝试导入错误:未从'./authReducer'导出'authReducer'。 ”

[英]“Attempted import error: 'authReducer' is not exported from './authReducer'. ”

**actually, I'm trying to import a function from JS file called authReducer.js but I'm unable to do so. **实际上,我正在尝试从JS文件中导入一个名为authReducer.js的函数,但无法这样做。

In authReducer.js I tried to store that function in const variable in the name of authReducer and then tried to export it but Still same error 在authReducer.js中,我试图以authReducer的名称将该函数存储在const变量中,然后尝试将其导出,但仍然存在相同的错误

index.js index.js

import {combineReducers} from 'redux'

import {authReducer} from './authReducer' //I'm getting error here

export default combineReducers({
    auth:authReducer
});

authReducer.js authReducer.js

const initialState={
    isAuthenticated:false,
    user:{}
}


export default function(state=initialState,action){
    switch(action.type)
    {
        default:
            return state;
    }
};

Both are located in the same folder. 两者都位于同一文件夹中。

Change your import from: 从以下位置更改导入:

import { authReducer } from './authReducer'

to: 至:

import authReducer from './authReducer`'

Your import statement should look like this as your function is a default export. 您的import语句应如下所示,因为您的函数是默认导出。 You only use {} if it's a named export. 仅当{}是命名导出时,才使用。

import authReducer from './authReducer'

Default exports don't need curly braces around them, those are for named exports. 默认出口不需要花括号,它们用于命名出口。

/*  somewhere.js  */
const Potato = 5;
const Chernobyl = "hello";

export { Potato };
export default Chernobyl;

and then when importing: 然后在导入时:

import Chernobyl, { Potato } from "somewhere";
           ^           ^
       default       named

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM