GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — ng add @angular/pwa cannot find AppModule if imported through index.ts · Issue #11499 · angular/angular-cli

ng add @angular/pwa cannot find AppModule if imported through index.ts #11499

New issue
Copy link
New issue
Copy link
Open
Bug
Open
ng add @angular/pwa cannot find AppModule if imported through index.ts#11499
Bug
Copy link
Labels
area: @angular/pwafreq1: lowOnly reported by a handful of users who observe it rarelyOnly reported by a handful of users who observe it rarelyseverity3: brokentype: bug/fix
Milestone
needsTriage

Description

@madmath03
madmath03
opened on Jul 8, 2018
Issue body actions

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

Area

- [ ] devkit
- [x] schematics

Versions

$ node --version
v8.11.2
$ npm --version
5.6.0

Repro steps

  • Create an Angular 6 application
  • If not present, create a index.ts in the App module folder with at least the following content:
export * from './app.module';
  • In the main.ts, import the App module indirectly by using its parent folder:
import './polyfills.ts';

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { environment } from './environments/environment';
import { AppModule } from './app'; // works because ./app/index.ts exports AppModule

if (environment.production) {
    enableProdMode();
}

platformBrowserDynamic().bootstrapModule(AppModule);
  • Now use angular CLI to add PWA
$ ng add @angular/pwa --project <your-project-name-from-angular-json>

The log given by the failure

Installing packages for tooling via npm.

+ @angular/[email protected]
updated 1 package in 11.487s
Installed packages for tooling via npm.
Could not read file (/src/app.ts).

Desired functionality

Make PWA install work even when importing the AppModule indirectly (through an index.ts).

To be more accurate, the findBootstrapModulePath function from ng-ast-utils.d.ts should properly identify the AppModule path in this setup.

angular-cli/packages/schematics/angular/utility/ng-ast-utils.ts

Line 49 in 44086c6

export function findBootstrapModulePath(host: Tree, mainPath: string): string {

This method is called by updateAppModule from

angular-cli/packages/schematics/angular/service-worker/index.ts

Line 99 in 8ce5ef4

const modulePath = getAppModulePath(host, mainPath);

The failure occurs when trying to update the content of a file which does not exists. Checking the file exists and displaying a better message would also help.

Mention any other details that might be useful

The issue was encountered when attempting to add PWA to our NGXP Seed web side.

$ git clone https://github.com/Monogramm/ngxp-seed.git
$ git checkout develop
$ ng add @angular/pwa --project web

Since we managed to find out the root cause, the workaround of using the complete path will be used for now.

Reacted by Bogac Guven, Amir Savand and Farbfetzen

Activity

  1. clydin
    added
    area: @angular/pwa
    on Jul 9, 2018
  2. bogacg commented on Jul 13, 2018

    @bogacg
    bogacg
    on Jul 13, 2018
    More actions

    I had similar problem. In my case I'm using tsconfig path mapping and reference AppModule in main.ts with that reference:

    import { AppModule } from '@app/app.module';

    I get the same type of error: Could not read file (/src/@app/app.module.ts).

    Changing back only that reference to import { AppModule } from './app/app.module'; in main.ts results execution of ng add @angular/pwa as expected

    Reacted by Mathieu Brunot, Michał Dybich, Dmitry A. Efimenko, Alex Mantaut, Vlad Dumbrava, Vishal Naik, Danail Videv, Mike Voermans, Mikko Husari, Jason Yeomans and 39 more
    Reacted by Mikko Husari, Jason Yeomans, Miklós Kosárkár, adrien, Olsi Odobashi, EternalPirate, Amir Savand, raoulsigne and Claudia SG
    Reacted by Crhistian Ramirez, Patricio, Geraldine Herrera Garmendia, Amir Savand, Ahmad Almunajjed and Paulraj
    Reacted by xoferiff
    Reacted by DRiiFT KiinG
  3. madmath03 commented on Jul 19, 2018

    @madmath03
    madmath03
    on Jul 19, 2018
    Author
    More actions

    We went for the same solution of import { AppModule } from './app/app.module';.

    Knowing this workaround makes the issue less critical but it's still a bit weird to be forced to do this just to add a component 😉

  4. cedvdb commented on Oct 2, 2018

    @cedvdb
    cedvdb
    on Oct 2, 2018
    More actions

    it also doesn't find it if you have alias for imports

  5. ngbot
    added this to the needsTriage milestone on Jan 24, 2019
  6. kyliau
    added
    needs: investigationRequires some digging to determine if action is neededRequires some digging to determine if action is needed
    triage #1
    type: bug/fix
    on May 27, 2020
  7. kasir-barati commented on Jun 20, 2022

    @kasir-barati
    kasir-barati
    on Jun 20, 2022
    More actions

    Is this issue abandoned @kyliau? I faced in 2022. After 2 years this issue still exists 🤒?

    image

    You can reproduce the issue in this repo. Just do ng add @angular/material

    BTW I hope this issues resolve. @angular-robot

    Reacted by Lucas Simões
    Reacted by Lucas Simões
    Reacted by Lucas Simões
  8. alan-agius4
    removed
    triage #1
    on Jun 24, 2022
  9. alan-agius4
    added
    freq1: lowOnly reported by a handful of users who observe it rarelyOnly reported by a handful of users who observe it rarely
    severity3: broken
    and removed
    needs: investigationRequires some digging to determine if action is neededRequires some digging to determine if action is needed
    on Sep 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: @angular/pwafreq1: lowOnly reported by a handful of users who observe it rarelyOnly reported by a handful of users who observe it rarelyseverity3: brokentype: bug/fix

    Type

    Bug

    Projects

    No projects

      Milestone

      • needsTriageNo due date

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.