Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

171
Vistas
Disable eslint error in jsx

I have the below JSX in one of my react-native components

        <TouchableOpacity onPress={this.onEnableNotifications} style={{marginHorizontal: 10}}>
          <Image source={require('../../img/ic_warning.png')} style={{tintColor: colorThemes.Blue.red}}/>
        </TouchableOpacity>

I get the following ESLint error:

'require' is not defined. (no-undef)

I have tried adding line { // eslint-disable-line no-undef } after Image but that gives a parsing error. How can I get rid of this error just for that line.

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

On your .eslintrc file:

{
    "globals":{
        "require": true
    }
}
over 4 years ago · Santiago Trujillo Denunciar

0

I've read there are some jsx quirks so try separating it out:

<TouchableOpacity onPress={this.onEnableNotifications} style={{marginHorizontal: 10}}>
  <Image
    source={require('../../img/ic_warning.png')} // eslint-disable-line no-undef
    style={{tintColor: colorThemes.Blue.red}}
  />
</TouchableOpacity>

Or you can define it above.

const warningImage = require('../../img/ic_warning.png'); // eslint-disable-line no-undef

....

<TouchableOpacity onPress={this.onEnableNotifications} style={{marginHorizontal: 10}}>
  <Image source={warningImage} style={{tintColor: colorThemes.Blue.red}}/>
</TouchableOpacity>

If this is a static path though, I would just define it outside the react class/function entirely, as an import.

over 4 years ago · Santiago Trujillo Denunciar

0

In order to disable eslint warnings with comments inside jsx use

{ /* eslint-disable no-undef */ }
     <div>element causing warning </div>
{ /* eslint-enable no-undef */ }

A single line comment does not work:

{ /* eslint-disable-line no-undef */ }

Also see

https://github.com/eslint/eslint/issues/7030

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda