I\'m getting following error when I build the Angular app using \"ng build --prod\". This is working when I build with Angular 4 and getting error with Angular 5. With Angul
In my case, the error was because of multiple definitions of the same class in various files. This happened due to copy-paste codes by some developer.
Angular 5 and specifically angular cli 1.5 has default ahead of time compilation turned on and it needs to know module for all components/pipes etc. that it finds in your project folder if you have some components that aren't declared in any module it will throw errors.
You can either declare TimeAgoPipe
in some module:
@NgModule({
declarations: [TimeAgoPipe, ...]
})
export class AppModule {}// for example can be any other used module
or try running build without ahead of time compilation resulting code will work slower
ng build --prod --aot=false
third way if you don't use that pipe at all you can add it to excluded files in tsconfig.json
{
...
"exclude": [ "path/to/unused/component.ts", ... ]
}
In my case, there were two components what are named same. I removed one of them and it's fixed.
For me it didn't work even when component was there in declarations. So, I removed the component from declarations and from imports as well. And then I readded it by using Visual Studio code intellisense to auto complete component name in declarations and using auto import to import component at the top of the module file. And to my surprise it worked.
If any of the above solutions didn't work for you, then this is also worth trying.
I had exactly the same issue and can offer a workaround although not sure why this specific pipe is not being successfully picked up by the aot build:
Workaround
Copy the time-ago-pipe.ts from node_modules/time-ago-pipe and just copy this file into your own project.
Add it to your declarations in your module as normal and import this into your imports e.g:
import { TimeAgoPipe } from './_pipes/time-ago-pipe';
This will then compile successfully in AOT build and you can still use the pipe.
Ran into this issue and wanted to consolidate existing suggestions, and suggest some general strategies when nothing else worked for me:
Pipe
; I was using custom Pipe
injected straight into an Angular Service
.Pipe
, the issue went away; so I removed the Pipe
transform -- I moved the transformation to a different Service
, stopped depending on Pipe
altogether.declarations
(and exports
) properties of your NgModule
node_modules
), copy the Pipe to your own project (if possible), and/or re-export the Pipe from one of your NgModule
exclude
property of the tsconfig.json
(this may not be an option for everyone)
ng build --aot=false
(may be a faster build, but then creates a non-optimized app; learn more about AOT)
declaratations
array of two or more different NgModule
s
import { YourPipe } from './yoUr-pippe.ts'
, make sure there are no typos or capitalization issues in your import statement, especially the filename
'./yoUr-pippe.ts'
has a capitalization issue, and a typo, and shouldn't use the ts
file extension (that's implied in Typescript))Ensure any ts
file which uses the problematic Pipe/Component, lives in an NgModule
which import
s the NgModule
that defined the Pipe/Component!
AModule
, defines AComponent
, which uses BPipe
, defined in BModule
, then AModule
must import
the BModule
NgModule
dependency tree. I used a "shared module" pattern so my Pipe could be re-used in multiple places.Ensure there are no circular NgModule
dependencies, like in these examples
If you are able, Upgrade NodeJS itself and/or angular
and its tools (angular-cli
, etc)
Cannot determine the module...
issue (which stopped happening!)Be careful about using index.ts files aka "barrel files", and the order of exports
index.ts
file issues)A general problem-solving approach : Remove / comment-out any references to the problematic file,
Can't bind to '___' since it isn't a known property of '___'
, or Property '___' does not exist on type '___'. Did you mean '____'
, or Expected 0 arguments, but got 1.
)ng build
works. When I uncommented/added all my code back... my ng build
no longer had the Cannot determine the module...
issue