当我使用"ng build --prod"构建Angular应用程序时,我遇到了以下错误.当我使用Angular 4构建并且使用Angular 5获得错误时,这是有效的.使用Angular 5"ng serve"工作正常.
错误中的错误:无法在mypath/node_modules/time-ago-pipe/time-ago-pipe.ts中确定类TimeAgoPipe的模块!将TimeAgoPipe添加到NgModule以修复它.
获取https://www.npmjs.com/package/time-ago-pipe的错误
有解决方案吗
Ana*_*ali 24
检查区分大小写
import { MyComponent } from "./User/my-component";
Run Code Online (Sandbox Code Playgroud)
在我的情况下,问题是在我的import语句中使用U作为资本创建了文件夹用户.但实际上在磁盘上它是小例子.当我在import语句中将文件夹重命名为user(带小写的情况下)时,它对我有用.
import { MyComponent } from "./user/my-component";
Run Code Online (Sandbox Code Playgroud)
因此,请检查导入路径的区分大小写.
Xes*_*nix 14
Angular 5和特定角度cli 1.5默认提前编译打开它需要知道它在项目文件夹中找到的所有组件/管道等的模块,如果你有一些未在任何模块中声明的组件它将抛出错误.
您可以TimeAgoPipe
在某个模块中声明:
@NgModule({
declarations: [TimeAgoPipe, ...]
})
export class AppModule {}// for example can be any other used module
Run Code Online (Sandbox Code Playgroud)
或者尝试在没有提前编译的情况下运行构建,结果代码将运行得更慢
ng build --prod --aot=false
Run Code Online (Sandbox Code Playgroud)
第三种方法,如果你根本不使用那个管道,你可以将它添加到排除的文件中 tsconfig.json
{
...
"exclude": [ "path/to/unused/component.ts", ... ]
}
Run Code Online (Sandbox Code Playgroud)
我有完全相同的问题,并且可以提供一种解决方法,尽管不确定为什么aot构建无法成功使用此特定管道:
解决方法
从node_modules / time-ago-pipe复制time-ago-pipe.ts,然后将此文件复制到您自己的项目中。
像往常一样将其添加到模块中的声明中,并将其导入到导入中,例如:
import { TimeAgoPipe } from './_pipes/time-ago-pipe';
Run Code Online (Sandbox Code Playgroud)
然后,它将在AOT构建中成功编译,并且您仍然可以使用管道。
遇到这个问题并想整合现有的建议,并在没有其他方法对我有用的情况下提出一些一般策略:
Pipe
; 我使用的是Pipe
直接注入 Angular 的自定义Service
。Pipe
,问题就消失了;所以我删除了Pipe
转换——我将转换移到了一个不同的Service
,Pipe
完全取决于。declarations
exports
NgModule
node_modules
),请将管道复制到您自己的项目(如果可能),和/或从您的项目之一重新导出管道NgModule
exclude
tsconfig.json
ng build --aot=false
情况下构建(可能是更快的构建,但随后会创建一个未优化的应用程序;了解有关 AOT 的更多信息)
declaratations
数组中 NgModule
import { YourPipe } from './yoUr-pippe.ts'
,确保导入语句中没有拼写错误或大小写问题,尤其是文件名
'./yoUr-pippe.ts'
存在大小写问题和拼写错误,不应使用ts
文件扩展名(Typescript 中隐含的))确保任何ts
文件,其使用有问题的管道/组件,生活在NgModule
其中import
S中NgModule
所定义的管道/组件!
AModule
限定AComponent
,其用途BPipe
,在定义的BModule
,然后AModule
必须import
在BModule
NgModule
依赖树。我使用了“共享模块”模式,因此我的 Pipe 可以在多个地方重复使用。如果可以,升级NodeJS
自身和/或angular
及其工具(angular-cli
等)
Cannot determine the module...
问题(这不再发生了!)要小心使用index.ts
文件又名“桶文件”,以及顺序exports
index.ts
文件问题)一般解决问题的方法:删除/注释掉对有问题文件的任何引用,
Can't bind to '___' since it isn't a known property of '___'
、 或Property '___' does not exist on type '___'. Did you mean '____'
、 或Expected 0 arguments, but got 1.
)ng build
工作正常。当我取消注释/添加我所有的代码时......我ng build
不再有这个Cannot determine the module...
问题 归档时间: |
|
查看次数: |
15330 次 |
最近记录: |