gulp-webpack is unable to locate node packages

Currently working on developing a modern Angular application.

I have opted to use gulp-webpack for quick development builds. To handle my TypeScript bundling and node modules dependencies, I am relying on webpack. However, it seems that gulp-webpack is not resolving imports to the node_modules directory automatically! This issue results in numerous TypeScript errors stating that it cannot locate certain modules, such as angular, causing them to be missing from my bundle.

Below is an abbreviated version of my gulpfile:


// Dependencies
var gulp = require('gulp');
var path = require('path');
// var concat = require('gulp-concat');
var expect = require('gulp-expect-file');
var plumber = require('gulp-plumber');
var sourcemaps = require('gulp-sourcemaps');
// var uglify = require('gulp-uglify');

// Plugins
var webpack = require('gulp-webpack');
var sass = require('gulp-sass');
var nodemon = require('gulp-nodemon');
var ts = require('gulp-typescript');
var del = require('del');
var rename = require('gulp-rename');
var inject = require('gulp-inject-string');

// Task to bundle client-side JavaScript
gulp.task('js', function() {
    gulp.safeSrc('src/app/main.ts')
        .pipe(sourcemaps.init())
        .pipe(webpack({
            context: __dirname,
            entry: ['./src/app/main'],
            resolve: {
                modulesDirectories: ["./node_modules"],
                extensions: ['.ts', '.js']
            },
            resolveLoader: {
                root: path.resolve(__dirname, 'node_modules')
            },
            output: {
                filename: "bundle.js"
            },
            module: {
                loaders: [{
                        test: /\.js$/,
                        loader: 'babel-loader'
                    },
                    {
                        test: /\.ts$/,
                        loader: 'ts-loader'
                    }
                ],
            },
        }))
        .pipe(sourcemaps.write())
        .pipe(gulp.dest('public'))
})

The issues start with my app.component.ts — encountering errors when importing 'zone.js'

ERROR in ./src/app/app.component.ts Module not found: Error: Cannot resolve module 'zone.js' in C:\appdir\src\app @ ./src/app/app.component.ts 12:0-18


import 'zone.js';
import 'reflect-metadata';
import { Component } from '@angular/core';

import { Observable } from 'rxjs/Rx';
import { Store } from '@ngrx/store';
import { AppStore } from '../models/application-store';
import { AuthSvc } from './auth/auth.svc';

import { Action } from './actions'

@Component({
    selector: 'my-app',
    template: `
    <div class="app">
     <main-header>
     </main-header>
     <router-outlet></router-outlet>
   </div>`

})

export class AppComponent {
    error: any;
    showNgFor = false;

    constructor() {

    }
}

Any insights into what might be causing this issue?

Answer №1

gulp-webpack may be considered outdated in the world of npm packages.

To stay current with webpack 3.0, consider switching to webpack-stream.

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

Unleashing the power of Typescript enums in conjunction with external modules through browserify

Previously, I utilized TypeScript internal modules and included numerous script tags to initialize my app. Now, I am in the process of transitioning the project to utilize external modules (using browserify), but I have hit a roadblock when it comes to con ...

Is it necessary to include Babel when integrating Webpack?

After reading an informative article, it is highlighted that Babel’s plugin-syntax-dynamic-import plays a crucial role in enabling lazy loading. Without this, the syntax const AppHome= () => import("@/components/AppHome"); will not be compiled by webp ...

Modifying the response header in a node.js middleware: A step-by-step guide

I've been researching this question extensively on Google, but unfortunately, none of the solutions seem to work for me. The issue I'm facing is related to adding a specific property to the response header called "isAuth," which needs to be set ...

Understand and extract data from a JSON array using Typescript

Here is a JSON response I received from a remote server: { "string": [ { "id": 223, "name": "String", "sug": "string", "description": "string", "jId": 530, "pcs": [{ "id": 24723, "name": "String", ...

Tips for enforcing a mandatory type with TypeScript

Creating a custom type called InputType with optional properties like this: export type InputType = { configJsonUrl?: string; configJsObject?: DataType; rawData?: { [key: string]: string }; action?: () => void; }; export type DataType = { id ...

What is the most effective way to use a withLatestFrom within an effect when integrating a selector with props (MemoizedSelectorWithProps) sourced from the action?

I am struggling to utilize a selector with props (of type MemoizedSelectorWithProps) in an effect inside WithLatestFrom. The issue arises because the parameter for the selector (the props) is derived from the action payload, making it difficult for withLat ...

Unable to resolve all parameters for the RouterUtilities class

My goal is to develop a RouterUtilities class that extends Angular's Router. Despite the app running and compiling smoothly, when I run ng build --prod, it throws an error message like this: ERROR in : Can't resolve all parameters for RouterUtil ...

Instructions for enabling the touch slider feature in the Igx carousel component with Angular 6 or higher

Looking to enable the touch slider for Igx carousel using angular 6+? I am trying to implement the igx carousel for image sliding with reference from a stackblitz demo (https://stackblitz.com/edit/github-j6q6ad?file=src%2Fapp%2Fcarousel%2Fcarousel.compone ...

The PKIJS digital signature does not align with the verification process

Explore the code snippet below const data = await Deno.readFile("./README.md"); const certificate = (await loadPEM("./playground/domain.pem"))[0] as Certificate; const privateKey = (await loadPEM("./playground/domain-pk ...

Ensure that the method is triggered

I have a builder class that implements an interface which it is expected to build. However, I would like to enforce one method of this class to be called at compile time, rather than runtime. The class is designed to be used as a chain of method calls and ...

Using TypeScript to chain observables in a service and then subscribing to them in the component at the end

Working with Platform - Angualar 2 + TypeScript + angularFire2 Within my user.service.ts file, I have implemented the following code to initiate an initial request to a firebase endpoint in order to fetch some path information. Subsequently, I aim to util ...

Obtain redirected JSON data locally using Angular 5

Currently, I am working on retrieving JSON data which will be sent to my localhost through a POST method. The SpringBoot API controller will validate the JSON content before forwarding it to my localhost. My task is to intercept this JSON data when it is t ...

Utilizing the "as" keyword for type assertion in a freshly created react application using create-react-app leads to the error message `Parsing error: Unexpected token, expected ";"`

After creating a new CRA project using yarn create react-app my-app --template typescript, I encountered an error when trying to run the development server with yarn start: src/App.tsx Line 5:24: Parsing error: Unexpected token, expected ";" ...

Removing API request in React.js

My approach: deleteSample = () => { this.sampleService .deleteCall(this.props.id) .then((response) => { window.location.reload(false); }) .catch((error) => { console.log ...

checkbox with an option tag

I need help with implementing multi-select checkboxes inside an Angular 4 application. The checkboxes are not appearing next to the team names as intended. Can anyone assist me with this issue? Below is a snippet of my HTML code: <select class="form-c ...

I am encountering issues with running my tests using react-testing-library alongside TypeScript

Currently facing issues with react-testing-library in my TypeScript-based React project. Despite researching and following various tutorials, I am unable to resolve the problem. I have experimented with changing configurations in babel.config.js, tsconfig ...

An unexpected error occurs when attempting to invoke the arrow function of a child class within an abstract parent class in Typescript

Here is a snippet of code that I'm working on. In my child class, I need to use an arrow function called hello(). When I try calling the.greeting() in the parent class constructor, I encounter an error: index.ts:29 Uncaught TypeError: this.hello is ...

Failure of Styling Inheritance in Angular 2 Child Components from Parent Components

My Parent Component utilizes a Child Component. I have defined the necessary styles in the Parent CSS file, and these styles change appropriately when hovering over the div. However, the Child Component does not inherit the styling classes of the Parent Co ...

When defining a GraphQL Object type in NestJS, an error was encountered: "The schema must have unique type names, but there are multiple types named 'Address'."

Utilizing Nestjs and GraphQL for backend development, encountered an error when defining a model class (code first): Schema must contain uniquely named types but contains multiple types named "Address". Below is the Reader model file example: @ObjectType() ...

Jest test encounters an error due to an unexpected token, looking for a semicolon

I've been working on a Node project that utilizes Typescript and Jest. Here's the current project structure I have: https://i.stack.imgur.com/TFgdQ.png Along with this tsconfig.json file "compilerOptions": { "target": "ES2017", "modu ...