简体   繁体   English

尝试导入错误:“ApiRequests”未从“./ApiRequests”导出

[英]Attempted import error: 'ApiRequests' is not exported from './ApiRequests'

I am new in js and react,so:我是 js 新手并做出反应,所以:

i try to export js function:我尝试导出 js function:

App.js:应用程序.js:

import React from 'react';
import logo from './logo.svg';
import './App.css';
import { render } from 'react-dom';
import { LazyLog } from 'react-lazylog';    
import 'bootstrap/dist/css/bootstrap.min.css';
import { Dropdown  } from 'react-bootstrap';
import {ApiRequests} from './ApiRequests'


var textConst="";
var lines=ApiRequests.GetMockLogLines();
textConst=lines;

And ApiRequests.js:和 ApiRequests.js:

export function GetMockLogLines()
{
 let logs=[""]
 return logs;
}

So, when i compile js (o, my God) it breaks me:所以,当我编译 js(哦,我的上帝)时,它让我崩溃了:

Attempted import error: 'ApiRequests' is not exported from './ApiRequests'.

When i change it to:当我将其更改为:

 import ApiRequests from './ApiRequests'

-> ->

 Attempted import error: './ApiRequests' does not contain a default export (imported as 'ApiRequests').  

So, i just want to get function from another file.所以,我只想从另一个文件中获取 function 。 What i do wrong?我做错了什么?

And what difference between {} and without it? {} 和没有它有什么区别? (you can send me a link start to read,pls). (你可以给我一个链接开始阅读,请)。

There is no function named Apirequests in your file.您的文件中没有名为 Apirequests 的 function。 The function you are exporting is GetMockLogLines()您要导出的 function 是GetMockLogLines()

So your import should be所以你的进口应该是

import {GetMockLogLines} from './ApiRequests'

As for the importing difference betweent {} and without the curly braces is how you are exporting your stuff from your file.至于 {} 和没有大括号之间的导入区别是您如何从文件中导出内容。 There are two types of exports - Default export and named exports.有两种类型的导出 - 默认导出和命名导出。 One can have only one default export per file and it has to be imported without the curly braces.每个文件只能有一个默认导出,并且必须在没有花括号的情况下导入。

You can read more here - https://medium.com/@etherealm/named-export-vs-default-export-in-es6-affb483a0910您可以在此处阅读更多信息 - https://medium.com/@etherealm/named-export-vs-default-export-in-es6-affb483a0910

you need to import GetMockLogLines directly as it is a named import.您需要直接导入GetMockLogLines ,因为它是命名导入。 change your code to the following.将您的代码更改为以下内容。

 import { GetMockLogLines } from './ApiRequests' var lines=GetMockLogLines();

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

相关问题 尝试导入错误:'未从 - Attempted import error:' is not exported from 尝试导入错误:“App”未从“./App”导出 - Attempted import error: 'App' is not exported from './App' 尝试导入错误:“Typography”未从“antd”导出 - Attempted import error: 'Typography' is not exported from 'antd' 尝试导入错误:“必需”未从“是的”导出 - Attempted import error : 'required' is not exported from 'yup' 反应错误“尝试导入错误:'TodoItem'未从'./Todoitem'导出。” - error in react " Attempted import error: 'TodoItem' is not exported from './Todoitem'. " 尝试导入错误:未从“ d3”导出“行为” - Attempted import error: 'behavior' is not exported from 'd3' 尝试导入错误:“app”未从“firebase/app”导出(导入为“firebase”) - Attempted import error: 'app' is not exported from 'firebase/app' (imported as 'firebase') 尝试导入错误:“Navigate”未从“react-router-dom”导出 - Attempted import error: 'Navigate' is not exported from 'react-router-dom' 尝试导入错误:“SelectionPage”未从“./components/SelectionPage”导出 - Attempted import error: 'SelectionPage' is not exported from './components/SelectionPage' 尝试导入错误:“showErrorMessage”未从“../helpers/alerts”导出 - Attempted import error: 'showErrorMessage' is not exported from '../helpers/alerts'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM