Error loading npm linked custom library with aot
Please provide us with the following information:
OS?
Windows 7, 8 or 10. Linux (which distribution). Mac OSX (Yosemite? El Capitan?)
Mac OSX, El Capitan
Versions.
Please run
ng --version. If there's nothing outputted, please run in a Terminal:node --versionand paste the result here:
angular-cli: 1.0.0-beta.24
node: 6.9.2
os: darwin x64
@angular/common: 2.4.1
@angular/compiler: 2.4.1
@angular/core: 2.4.1
@angular/forms: 2.4.1
@angular/http: 2.4.1
@angular/platform-browser: 2.4.1
@angular/platform-browser-dynamic: 2.4.1
@angular/router: 3.4.1
@angular/compiler-cli: 2.4.1
Repro steps.
Was this an app that wasn't created using the CLI? What change did you do on your code? etc.
From a really fresh angular cli project.
Only adding in app.module.ts :
import { MessageModule } from 'my_lib';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
MessageModule.forRoot() // <-- include here
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
Adding one of the component in app.component.html
<my-message type="error">This is an error message</my-message>
And running
ng build --aot
The log given by the failure.
Normally this include a stack trace and some more information.
chunk {0} main.bundle.js, main.bundle.map (main) 1.48 kB {2} [initial] [rendered]
chunk {1} styles.bundle.css, styles.bundle.map, styles.bundle.map (styles) 1.77 kB {3} [initial] [rendered]
chunk {2} vendor.bundle.js, vendor.bundle.map (vendor) 1.06 MB [initial] [rendered]
chunk {3} inline.bundle.js, inline.bundle.map (inline) 0 bytes [entry] [rendered]
ERROR in Error encountered resolving symbol values statically. Calling function 'makeDecorator', function calls are not supported. Consider replacing the function or lambda with a reference to an exported function, resolving symbol Injectable in /Users/admin/dev/web-library/node_modules/@angular/core/src/di/metadata.d.ts, resolving symbol OpaqueToken in /Users/admin/dev/web-library/node_modules/@angular/core/src/di/opaque_token.d.ts, resolving symbol OpaqueToken in /Users/admin/dev/web-library/node_modules/@angular/core/src/di/opaque_token.d.ts
ERROR in ./src/main.ts
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in '/Users/admin/dev/web-library/ng24/src'
@ ./src/main.ts 4:0-74
@ multi main
ERROR in ./~/@angular/core/src/linker/system_js_ng_module_factory_loader.js
Module not found: Error: Can't resolve '/Users/admin/dev/web-library/ng24/src/$$_gendir' in '/Users/admin/dev/web-library/ng24/node_modules/@angular/core/src/linker'
@ ./~/@angular/core/src/linker/system_js_ng_module_factory_loader.js 69:15-36 85:15-102
@ ./~/@angular/core/src/linker.js
@ ./~/@angular/core/src/core.js
@ ./~/@angular/core/index.js
@ ./src/main.ts
@ multi main
Mention any other details that might be useful.
My message module declare and exports the message component, with inlined css/html.
It's Exported with a forRoot :
export class MessageModule {
public static forRoot(): ModuleWithProviders {
return {ngModule: MessageModule, providers: []};
}
}
my_lib is generated with ngc, with a .metadata.json near each d.ts. With following tsconfig parameters :
...
"target": "es5",
"module": "es2015",
...
"angularCompilerOptions": {
"skipTemplateCodegen": true
}
Thanks! We'll be in touch soon.
I've encountered this error when having a dependency installed from the local file directory. NPM5 creates a symlink which doesn't seem to want to play nice with the AOT compiler. I solved it by downgrading to NPM3 with npm install -g npm@3 which will by default install the dependency simulating an install from NPM, and use the package.json and .npmignore files. Alternatively, you may want to try something like the npm package npm install-local https://www.npmjs.com/package/install-local.
Hopefully, this helps someone else down the road.
It looks like npm@5 intentionally broke this: https://github.com/npm/npm/pull/15900
@Polyergic So what would be the fix now? I'm struggling...
@chrillewoodz, for the time being I'm both avoiding file: deps and avoiding AOT, and hoping at least AOT is fixed before I need the performance. Our internal deps are on our private github, which npm seems to handle correctly, it just makes some debugging tedious. If you need AOT now, AFAIK you can either just copy them into your tree or try to make them appear as git submodules.
just a note, this "paths" needs to be added to your tsconfig.json on your app , not your library folder, in case you are building a custom module.
SebastianSchenk answer works for me.
SebastianSchenk's answer does not work for me unfortunately. I am on v6.0.0 of everything. The error I am getting is
ERROR in ../@nims/ngutils/lib/collapsible-fieldset/collapsible-fieldset.component.ts(13,2): Error during template compile of 'CollapsibleFieldsetComponent' Function calls are not supported in decorators but 'ɵmakeDecorator' was called in 'Component' 'Component' calls 'ɵmakeDecorator'.
I am not using npm link per se, but lerna, which internally I think does pretty much the same thing. This error occurs even with the --preserve-symlinks option to ng build, which at one point was suggested as a solution (https://github.com/angular/angular-cli/issues/7097).
The component that it is complaining about is very simple. It just has a couple of @Input() properties and a short template. Looking at the component.js or component.metadata.json reveals nothing obvious.
@rtm Can you create a minimal repro of your issue?
@alexzuza Thanks for following up, but this problem magically solved itself, no idea how.
So maybe it's a VS Code thing or npm thing, I don't know, but somehow the file paths to our symlink'ed modules had their direct paths added (../../../patient/node_modules/*). We spent quite awhile trying to hunt down this issue, and apparently an automated process re-wrote the file paths in app.module.ts.
SHOULD BE:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { HttpClientModule } from '@angular/common/http';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { FlexLayoutModule } from '@angular/flex-layout';
import { FormsModule } from '@angular/forms';
OVERWRITTEN FILE PATHS:
import { BrowserModule } from '../../../patient/node_modules/@angular/platform-browser';
import { NgModule } from '../../../patient/node_modules/@angular/core';
import { RouterModule, Routes } from '../../../patient/node_modules/@angular/router';
import { HttpClientModule } from '../../../patient/node_modules/@angular/common/http';
import { BrowserAnimationsModule } from '../../../patient/node_modules/@angular/platform-browser/animations';
import { FlexLayoutModule } from '../../../patient/node_modules/@angular/flex-layout';
import { FormsModule } from '../../../patient/node_modules/@angular/forms';
For my case it is
"@angular/*": ["./node_modules/@angular/*"]
instead of
"@angular/*": ["../node_modules/@angular/*"]
in tsconfig.json. Then it works. 💯
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.