简体   繁体   中英

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

    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

    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

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'
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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