ESLint: Require statement not part of import state

2020-08-17 08:14发布

问题:

I'm trying to add a background image from react native BackgroundImage which needs to add source as source={require('*--iamge path --*')}

but my eslint throw Require statement not part of import statement. error. i have tried to import image in different ways for example:

 - const image = '--image path--'
 - import image = require('--image path--')
 - <BackgroundImage source={require('--image path--')}>

回答1:

you can disable this check in eslintrc.js file

module.exports = {
  ...
  rules: {
    ...
    '@typescript-eslint/no-var-requires': 0,
  }
}