【问题标题】:unable to export MaterialModule from shared.module.ts on Build time无法在构建时从 shared.module.ts 导出 MaterialModule
【发布时间】:2017-09-01 05:12:44
【问题描述】:

它正在 ng serve 上运行,但出现如下错误

ERROR in Unexpected value 'MaterialModule in E:/Code/employee-web/node_modules/@angular/material/typings/index.d.ts'

重要 由模块 'SharedModule in E:/Code/employee-web/src/app/shared/shared.module.ts' 编写。请添加一个 @NgModule 注释 n. ./src/main.ts 中的错误 未找到模块:错误:无法解析“E:\Code\employee-web\src”中的“./$$_gendir/app/app.module.ngfactory” 在“E:\Code\employee-web\src”中解析“./$$_gendir/app/app.module.ngfactory” 使用描述文件:E:\Code\employee-web\package.json(相对路径:./src) 字段“浏览器”不包含有效的别名配置 使用描述文件后:E:\Code\employee-web\package.json(相对路径:./src) 使用描述文件:E:\Code\employee-web\package.json(相对路径:./src/$$_gendir/app/app.module.ngfactory) 没有扩展 字段“浏览器”不包含有效的别名配置 E:\Code\employee-web\src\$$_gendir\app\app.module.ngfactory 没有 存在 .ts 字段“浏览器”不包含有效的别名配置 E:\Code\employee-web\src\$$_gendir\app\app.module.ngfactory.ts 没有 存在 .js 字段“浏览器”不包含有效的别名配置 E:\Code\employee-web\src\$$_gendir\app\app.module.ngfactory.js 没有 存在 作为目录 E:\Code\employee-web\src\$$_gendir\app\app.module.ngfactory 没有 存在 [E:\Code\employee-web\src\$$_gendir\app\app.module.ngfactory] [E:\Code\employee-web\src\$$_gendir\app\app.module.ngfactory.ts] [E:\Code\employee-web\src\$$_gendir\app\app.module.ngfactory.js] [E:\Code\employee-web\src\$$_gendir\app\app.module.ngfactory] @ ./src/main.ts 3:0-74 @multi ./src/main.ts

有人可以调查一下吗?

这里是共享模块

> @NgModule({
> 
>   declarations: [],   providers: [
>        ],   imports: [
>     HttpModule,
>     MaterialModule,
>        ],   exports: [
>     CommonModule,
>         //matrial MOdule
>     // MdTooltipModule,
>     // MdTabsModule,
>     // MdSlideToggleModule,
>     // MdIconModule,
>     // MdDialogModule,
>     // MdButtonModule,
>     // MdListModule,
>     // MdCardModule,
>     // MdToolbarModule,
>     // MdProgressSpinnerModule,
>     // MdProgressBarModule,
>     MaterialModule,
> 
> 
>       ] }) export class SharedModule { }

【问题讨论】:

  • 您使用的是什么版本的材料? MaterialModule 已被弃用一段时间,现在建议单独导入组件模块。
  • @yoonjesung 这里是版本 "@angular/material": "^2.0.0-beta.8",
  • 看起来您使用的是最新版本之一。与其导入/导出 MaterialModule,不如导入/导出单个组件模块。
  • 您可能来自以前版本的 angular/material,然后将其更改为 beta 8。尝试删除 node_modules 并再次执行 npm 安装
  • @Faisal 我已将所有模块更新到最新版本。现在一切正常

标签: angular typescript angular-material2 angular2-modules


【解决方案1】:

你可能做了以下事情:

import {MaterialModule} from "@angular/material";

@NgModule({
   declarations: [],
   providers: [],
   imports: [
     HttpModule,
     MaterialModule,
   ],
   exports: [
     CommonModule,
     MaterialModule,
   ]
})
export class SharedModule {}

但是,MaterialModule 已经被弃用了一段时间(我不记得确切的版本)。现在建议您单独导入组件模块:https://material.angular.io/guide/getting-started#step-3-import-the-component-modules

所以改成下面这样:

// Import whatever components you intend to use in this shared module here
import {MdButtonModule, MdCheckboxModule} from '@angular/material';

@NgModule({
   ...
   imports: [MdButtonModule, MdCheckboxModule],
   exports: [MdButtonModule, MdCheckboxModule],
   ...
})
export class SharedModule {}

您可以通过导入每个可用的组件模块,然后从共享模块中导出它们来模拟 MaterialModule 功能(厨房水槽)。

【讨论】:

  • 它给出的错误如下错误在 E:/Code/employee-web/node_modules/@angular/material/typings/‌​index.d.ts 中的意外值 'MdAutocompleteModule 由模块导入'E 中的 AppModule:/Code/employee-web/src/app/app.module.ts'。请添加“@NgModule”注解——
  • 嗯,很奇怪。你也安装了@angular/cdk 吗?我相信这也是一种依赖,但不确定这是否会影响任何事情。
  • 是的,这里已经安装了 @angular/cdk 版本 "@angular/animations": "^4.3.6", "@angular/cdk": "^2.0.0-beta.10" , "@angular/material": "^2.0.0-beta.10",
【解决方案2】:

我在使用 MaterialModule 中的 MdDialog 时遇到了同样的错误。 我刚刚修复了它,它可以工作。

我通过指定我在我的应用程序中使用的特定材料模块来修复它。

在我的 app.module.ts 中:

import { MdDialogModule } from '@angular/material';
imports: [
  MdDialogModule
]

在我的组件中:

import { MdDialog } from '@angular/material'
import { AuthorizationComponent } from '../authorization/authorization.component'

export class HomeComponent implements OnInit { 
  constructor(private dialog: MdDialog){}

  ngOnInit() {
  this.dialog.afterAllClosed
    .subscribe( () => {
          //make changes 
      })
   }

    sign_up() {
      this.dialog.open(AuthorizationComponent)  //open component
    }

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-09
    • 2023-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-18
    相关资源
    最近更新 更多