简体   繁体   English

尝试导入错误:'styles' 未从 './styles' 导出

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

I am trying to import styles from style.js file and the that file contains below code我正在尝试从style.js文件中导入 styles 并且该文件包含以下代码

    const export styles = {
    border: 'solid',
    textAlign : 'center',
    boxShadow : '2px 2px'
  }

But it shows the below error in that file但它在该文件中显示以下错误

'export' is not allowed as a variable declaration name.

But when I add the export keyword as shown below code但是当我添加export关键字时,如下代码所示

    const styles = {
    border: 'solid',
    textAlign : 'center',
    boxShadow : '2px 2px'
  }
    export default styles;

And trying to import in my component as并尝试将我的组件导入为

import * as styles from "./styles";

<div style={styles.styles}>
          Style
</div>

I am getting the below error我收到以下错误

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

How do I resolve it?我该如何解决?

Use this way style.js使用这种方式style.js

import { StyleSheet } from 'react-native';

export const styles = StyleSheet.create({

});

And trying to import in my component as并尝试将我的组件导入为

import styles from "./styles";

Try export as default尝试默认导出

 const styles = {
    border: 'solid',
    textAlign : 'center',
    boxShadow : '2px 2px'
  }
  export default styles;

I tried the below code it worked for me我尝试了下面对我有用的代码

 export const externalStyles = {
    color : 'red',
    backgroundColor: 'green'
}

暂无
暂无

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

相关问题 尝试导入错误:“样式”未从“./styles.scss”导出(导入为“样式”) - Attempted import error: 'styles' is not exported from './styles.scss' (imported as 'styles') 尝试导入错误:“useThemeVariants”未从“@material-ui/styles”导出 - Attempted import error: 'useThemeVariants' is not exported from '@material-ui/styles' 尝试导入错误:“fade”未从“@material-ui/core/styles”导出 - Attempted import error: 'fade' is not exported from '@material-ui/core/styles' 尝试导入错误:“alpha”未从“@material-ui/core/styles”导出 - Attempted import error: 'alpha' is not exported from '@material-ui/core/styles' 尝试导入错误:“makeStyles”未从“@material-ui/core/styles”导出 - Attempted import error: 'makeStyles' is not exported from '@material-ui/core/styles' 尝试导入错误:'未从 - Attempted import error:' is not exported from “尝试导入错误:未从&#39;./authReducer&#39;导出&#39;authReducer&#39;。 ” - “Attempted import error: 'authReducer' is not exported from './authReducer'. ” 尝试导入错误:“createstore”未从“redux”导出 - Attempted import error: 'createstore' is not exported from 'redux' 尝试导入错误:“ApiRequests”未从“./ApiRequests”导出 - Attempted import error: 'ApiRequests' is not exported from './ApiRequests' 尝试导入错误:“DatePicker”未从“格式塔”导出 - Attempted import error: 'DatePicker' is not exported from 'gestalt'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM