"Encountering issues with DefinePlugin when using the combination of Ionic, Angular, Webpack,

I'm trying to incorporate my process.env variable into the webpack Bundle using DefinePlugin. Here's the snippet of code in my webpack config:

plugins: [
    new webpack.DefinePlugin({
        'process.env': JSON.stringify(process.env)
    }),
    ionicWebpackFactory.getIonicEnvironmentPlugin(),
    ionicWebpackFactory.getCommonChunksPlugin()
],

In my package.json file, I have the following configuration:

    "@ionic/app-scripts": "3.1.9",
    "@types/jasmine": "^2.8.6",
    "@types/node": "^9.6.6",
    ...
    "html-loader": "^0.5.5",
    ....
    "null-loader": "^0.1.1",
    "ts-loader": "^4.0.0",
    "ts-node": "^6.0.0",
    "tslint": "^5.9.1",
    "tslint-eslint-rules": "^5.1.0",
    "typescript": "~2.6.2",
    "webpack": "^4.6.0"
 },
 "config": {
    "ionic_webpack": "./config/webpack.config.js"
 },

I have a service that utilizes the process.env injected by the plugin:

import { Injectable } from '@angular/core';

declare var process: {
   env: any
};

@Injectable()
export class ConfigurationService {

However, when I compile using yarn or npm, I encounter the following error:

 [10:28:04]  ionic-app-script task: "build"
 [10:28:04]  TypeError: Cannot read property 'compilation' of undefined
 TypeError: Cannot read property 'compilation' of undefined
      at DefinePlugin.apply ...\node_modules\webpack\lib
 \DefinePlugin.js:42:18)
 at Compiler.apply ( ...\node_modules\tapable\lib\Tapable.js:375:16)

I've searched online for a solution but couldn't find a similar issue. Thank you for your assistance.

Julien.

Answer №1

Encountered the same issue here. The solution I found was to ensure that all loaders were included in the devDependencies section and updated to their latest versions.

Please double-check these steps.

Answer №2

attempt this:

const webpackDefinePlugin = new webpack.DefinePlugin({
  'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Angular HTTP Interceptor encountering issue with TypeError: (0 , x.fromPromise) function is not recognized

I have implemented the following code snippet to attach reCAPTCHA v3 to an HTTP Request: @Injectable() export class RecaptchaInterceptor implements HttpInterceptor { constructor(private recaptchaService: ReCaptchaService) { } intercept(httpRequest: HttpRe ...

How to navigate to the bottom of a webpage with Angular 4 using TypeScript's onClick event

Within my component, I have a template that looks like the following. When this div is clicked, the intention is to scroll to the bottom of the page. `<section><div onclick='scrollDown()'>Goto Reports</div></section><d ...

Supertest and Jest do not allow for sending JSON payloads between requests

Below is the test function I have written: describe("Test to Create a Problem", () => { describe("Create a problem with valid input data", () => { it("Should successfully create a problem", async () => { const ProblemData = { ...

Integrating an API with a Discord bot using an embedded link in Discord.js

I am currently in the process of creating a bot that can generate and embed links to display manga titles, tags, and other information based on user-input digits. I have been exploring an API called this and I am eager to learn the most effective method ...

Angular Universal experiences issues with route functionality after page reloads

Recently deployed an Angular Universal web app on Firebase. While all routes within the application are functioning properly, encountering errors when trying to access them externally. Below is the error message: functions: Starting execution of "ssr" ⚠ ...

What is the method to insert a new <input> element after the last input field has been filled in

I recently started working on a form using StackBlitz, but I've hit a roadblock and need some guidance on how to proceed. My goal is to achieve a similar effect like the one shown in this gif: https://i.stack.imgur.com/76nsY.gif and I'd like to ...

How can I show the localStorage value in an HTML5 template using Angular2?

I have two keys stored in localStorage and I want to display one of them on my template. I'm having trouble accessing these values. I even created an interface specifically for storing the value of the currentUser key from localStorage. How should I g ...

Enhancing Styled Components in Material-UI with custom props and themes using Typescript

I am exploring the use of the Material UI styled components API to incorporate both a custom theme and some props into a specific custom element. Although I have managed to get either a custom theme or props working individually, I am struggling to make t ...

How to effectively utilize TypeScript in a team environment using both Atom and VSCode?

Our team utilizes TypeScript with both Atom and VSCode as our editors, but we are facing challenges with the tsconfig.json file. VSCode is not recognizing the typings, causing the namespace for 'ng' (for Angular 1.x) to be unknown in VSCode. Wh ...

Incorporating an NPM module into a React file: Webpack encounters resolution issues

After reviewing information from this source and here, the process of publishing a react module to NPM and then using it in another project while having the component in the node_modules directory should be as follows: Create and export a module Specify ...

What is the reason behind the angular http client's inability to detect plain text responses?

When I make a call to httpClient.get, I notice in Fiddler that both the request and response headers have text/plain format. Request: Accept: application/json, text/plain, */* Response: Content-Type: text/plain; charset=utf-8 Even though I am returning a ...

When a dialog box is displayed, a scrollbar will automatically appear

I've encountered a strange issue while working with Angular dialogs: A vertical scrollbar unexpectedly appears, even though I've set the dialog to have a fixed width. component.ts const dialog = this.dialog.open(DialogComponent, { width: ...

Switching between various components based on conditions within the same route in Angular

My goal is to have 2 separate views, one for the homepage and another for authentication. I want to display the LoginComponent on the route '/' and the SignupComponent on the route '/signup' if the user is not logged in, otherwise rende ...

Calculate the sum of elements within an array

I've been attempting to calculate the sum of values in an array based on different levels, but so far I haven't had much success. Here are the data I'm working with (stored in a variable called totalByLevel): https://i.stack.imgur.com/rOP9 ...

The function is trying to access a property that has not been defined, resulting in

Here is a sample code that illustrates the concept I'm working on. Click here to run this code. An error occurred: "Cannot read property 'myValue' of undefined" class Foo { myValue = 'test123'; boo: Boo; constructor(b ...

Is there a hashing algorithm that produces identical results in both Dart and TypeScript?

I am looking to create a unique identifier for my chat application. (Chat between my Flutter app and Angular web) Below is the code snippet written in Dart... String peerId = widget.peerid; //string ID value String currentUserId = widget.currentId ...

Can social login be used to add Firebase users to the user database?

When a user logs in through a social provider like Facebook, does Firebase automatically include them in the Firebase Authentication/User database? In simpler terms, if Christine signs in with Facebook, will Firebase save her Email address, first name, et ...

What is the best way to consistently and frequently invoke a REST API in Angular 8 using RxJS?

I have developed a REST API that retrieves a list of values. My goal is to immediately invoke this API to fetch values and store them in a component's member variable. Subsequently, I plan to refresh the data every five minutes. Upon conducting some ...

End-to-End Testing in Angular 2

Recently, I embarked on my Angular 2 journey and started exploring e2e testing. One challenge I encountered was trying to close a Bootstrap 4 modal by clicking in a blank area using Protractor. I attempted the following methods: it('should close the ...

I want to showcase a Python array within an Angular framework

Here is an example array: [ { "TO":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c2b6a7b1b682a5afa3abaecca1adaf">[email protected]</a>", "FROM":"<a href="/cdn-cgi/l/email-protection" class="__ ...