Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ng add @angular/material cannot find AppModule if imported through index.ts  #12729

Closed
@ajaypbarokar

Description

@ajaypbarokar

Bug Report or Feature Request (mark with an x)

  • bug report -> please search issues before submitting
  • feature request

Area

  • devkit
  • schematics

Versions
node --version
v10.10.0
npm --version
6.4.1

ng --version

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 7.0.2
Node: 10.10.0
OS: win32 x64
Angular: 7.0.0
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.10.2
@angular-devkit/build-angular     0.10.2
@angular-devkit/build-optimizer   0.10.2
@angular-devkit/build-webpack     0.10.2
@angular-devkit/core              7.0.2
@angular-devkit/schematics        7.0.2
@angular/cdk                      7.0.1
@angular/cli                      7.0.2
@angular/material                 7.0.1
@ngtools/webpack                  7.0.2
@schematics/angular               7.0.2
@schematics/update                0.10.2
rxjs                              6.3.3
typescript                        3.1.3
webpack                           4.19.1

Repro steps

Create an Angular 7 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 { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppModule } from './app';
import { environment } from './environments/environment';

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

platformBrowserDynamic()
  .bootstrapModule(AppModule)
  .catch(err => console.error(err));

Now use angular CLI to add material

 ng add @angular/material 

The log given by the failure :

ng add @angular/material
Installing packages for tooling via npm.
npm WARN @angular/[email protected] requires a peer of @angular/[email protected] but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ @angular/[email protected]
added 1 package and audited 39127 packages in 31.058s
found 0 vulnerabilities

Installed packages for tooling via npm.
? Enter a prebuilt theme name, or "custom" for a custom theme: custom
? Set up HammerJS for gesture recognition? No
? Set up browser animations for Angular Material? Yes
UPDATE package.json (1376 bytes)
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

added 2 packages from 1 contributor and audited 39130 packages in 23.409s
found 0 vulnerabilities

Could not read Angular module file: /src/app.ts

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions