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

449
Views
Angular: la variable webpack definePlugin no está definida

Estoy tratando de inyectar variables en mi código a través de definePlugin de Webpack.

Y después de leer numerosas publicaciones, nada parece funcionar. tengo la sensacion de que me falta algo...

La configuración de mi paquete web es:

 webpack = require('webpack'); module.exports = { plugins: [ new webpack.DefinePlugin({ $TEST: JSON.stringify(true), $ENV: { ENVIRONMENT: JSON.stringify(process.env.ENVIRONMENT) || 'localhost', API_URL: JSON.stringify(process.env.API_URL) } }) ] };

Creé el archivo typing.d.ts para declarar variables:

 declare let $ENV: Env; declare let $TEST: boolean; interface Env { ENVIRONMENT: string; API_URL: string; }

entonces estoy tratando de registrar variables en mi archivo main.ts:

 console.log('Test ' + $TEST); console.log('Environment :', $ENV.ENVIRONMENT);

Pero recibo el siguiente error cuando ejecuto el comando 'ng serve'

ingrese la descripción de la imagen aquí

Estoy usando :

  • paquete web: 5.54.0
  • "@constructores angulares/paquete web personalizado": "^12.1.2",
  • "@angular-devkit/build-angular": "~12.2.7",
  • "@angular/cli": "~12.2.7",

¿Alguien tiene alguna idea para arreglarlo por favor?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Esto solo funcionará para ng build , para ng serve necesitaremos agregar otro constructor angular personalizado a nuestro angular.json:

 "serve": { "builder": "@angular-builders/custom-webpack:dev-server", "options": { "browserTarget": "app:build" }, "configurations": { "production": { "browserTarget": "app:build:production" }, "ci": { "progress": false } } },

Importante, algunas otras publicaciones mencionan el uso de @angular-builders/dev-server:generic builder.

Pero este está en desuso (ver migración de constructores angulares )

@angular-builders/dev-server:generic ha quedado obsoleto. Utilice @angular-builders/custom-webpack:dev-server en su lugar.

over 4 years ago · Santiago Trujillo 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!