Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

190
Views
webpack DefinePlugin process.env.NODE_ENV no está definido

No soy muy bueno con las tecnologías front-end... Entonces, si tengo expectativas equivocadas, corríjame a mí o a mi código. He creado un repositorio con código que permite reproducir el problema. Aquí está el enlace: https://github.com/ffatheranderson/webpack-issue-reproduction

como se describe en readme.md del proyecto:

========================================

  • ¿Qué espero? - Espero que después de ejecutar el comando npm run watch , el archivo result/bundle.js generado tenga estas líneas:
 ... var _environment = 'development'; var _ANOTHER_VARIABLE = "another variable value"; ...
  • ¿Cuál es el resultado real? - después de ejecutar el comando npm run watch - el archivo result/bundle.js generado contiene estas líneas:
 ... var _environment = undefined; var _ANOTHER_VARIABLE = "another variable value"; ...
  • ¿Por qué tengo tales expectativas? - debido a estas líneas:
 ... plugins: [ new webpack.DefinePlugin({ ENVIRONMENT: JSON.stringify(process.env.NODE_ENV), ANOTHER_VARIABLE: JSON.stringify("another variable value"), }) ] ...

en el archivo webpack.config.js .

Como puede ver, la variable _environment no se inicializa con el valor de development como se promete aquí: https://webpack.js.org/configuration/mode/

========================================

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

_environment no está undefined porque la variable de entorno NODE_ENV no está definida. Puedes resolver esto en uno de tres:

  1. Invocando npm run watch --node-env=development : https://webpack.js.org/api/cli/#node-env
  2. Exportando NODE_ENV en su sesión de shell actual:
     $ export NODE_ENV=production; npm run watch
  3. Actualizar su configuración para especificar el valor de alguna otra fuente (por ejemplo, un argumento --env , un archivo en el disco, codificarlo, etc.)
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!