Closed Davy-F closed 7 years ago
After some digging, if I remove the index.d.ts file the error gets replaced with a new one.
Error: Error encountered resolving symbol values statically. Function calls are not supported. Consider replacing the function or lambda with a reference to an exported function (position 5342:25 in the original .ts file), resolving symbol DashboardService in C:/Development/AppTemplate/Application/WebClient/node_module s/commonlibrary/index.js, resolving symbol DashboardComponent in C:/Development/A ppTemplate/Application/WebClient/src/components/page-components/dashboard/dashbo ard.component.ts, resolving symbol DashboardComponent in C:/Development/AppTempl ate/Application/WebClient/src/components/page-components/dashboard/dashboard.com ponent.ts
So at least I can now possibly pinpoint where the code might be falling over within the CommonLibrary, perhaps due to not being compatible with AOT??
This is the line in question:
5342: var DashboardService = (function () {
...changing it to...
var DashboardService = (export function () {
...fixes the issue and then moves on to the next error.
After going through and fixing these, nope. Back to the original error. Hmm...
@Davy-F — Have you set up the path mapping as outlined in step 12 of https://github.com/jvandemo/generator-angular2-library#consuming-your-library-during-development?
Thanks!
Hi @jvandemo. Yes , I have. Here's my tsconfig file:
{
"compilerOptions": {
"baseUrl": "",
"target": "es5",
"module": "es2015",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": ["es2015", "dom"],
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true,
"typeRoots": [
"./node_modules/@types/"
],
"paths": {
"@angular/*": ["./node_modules/@angular/*"],
"rxjs/*": ["./node_modules/rxjs/*"]
}
},
"files": [
"src/app.module.ts",
"src/main.ts"
],
"angularCompilerOptions": {
"genDir": "aot",
"skipMetadataEmit" : true
}
}
I mentioned this in another similar issue. And it might not help but here goes anyway: Ensure that the name attribute at the top of package.json and ./src/package.json and the flatModuleId in ./src/tsconfig.es5.json are the same. I had the same error and it was because I renamed something and forgot to check these places.
@broweratcognitecdotcom Thank you for your reply. Unfortunately doesn't help out my issue as the name attribute is the same, but might always help out someone else out in the future.
That you add your components to your imports: [] for your module seems strange to me. I'm not saying it is incorrect. I am just wondering why you do that since adding them to declarations and optionally to exports should be enough. I don't do this. I don't know what effect it has, but in my case, I don't have this error. My module does not contain nearly as many parts as yours.
@broweratcognitecdotcom They've only been added to Declarations and Exports in the library module, which I believe is standard practice? I've updated my original code to make this clearer. Thanks for your help.
"only been added to Declarations and Exports" ... yes, I believe that is standard practice, although I see people adding components to imports sometimes and always wonder why. Thanks for updating. Try commenting out everything you're importing in index.ts. Build the lib, then build the app. See if it works. then start uncommenting stuff a bit at a time and repeat...
@Davy-F i am facing the same issue and i think it's because of order of import/export *
statements. I already faced similar issue and it was relatively easy to reorder things. But since then library is large and hard to try this approach.
I am using different approach for testing (consuming) library than npm link
. It is not ideal, but works. Try if it works for you.
dist
folder (https://stackoverflow.com/a/8089029). Just don't commit that change to your git.Theoretically this installs the same code of library if it would be installed from npm registry.
I bet if you switch from using npm link to using an in-house npm repo, your problem would be solved. Is this possible? One other thing I forgot to mention is that I set all of the versions of everything to the same version in all of my package.json files, including my libraries and apps, and don't use ~ or ^. If I add any dependency outside of what the generator gives me, I add it to both dependencies, and peerDependencies in package.json and ./src/package.json of my library. Maybe this is overkill, but I can build --aot and --prod and it's all working very nicely w/ version 9.0.0 of the generator.
@tytskyi @robertbrower-technologies Unfortunately I'm not using npm link and using VSTS as a private repository. I have been testing the library by copying and pasting the dist folder and still been getting the errors unfortunately.
I will go through the dependencies in the package.json files and update their ~/^, but I believe all versions are the same. Perhaps one or two could be missing from peerDependencies.
I'll also experiment with the import/export statements ordering.
I've somehow fixed this error. I wish I had more information on how exactly I fixed it , but I don't. I was going through my application and library, trying to amend all AOT compatibility fixes I could find. I also removed all console.logs in my library, because apparently this isn't supported.
I also amended all tsconfig files so they had paths
included.
"paths": {
"@angular/*": ["../node_modules/@angular/*"],
"rxjs/*": ["../node_modules/rxjs/*"]
},
It might've been that there was an incorrect value or issue with my tsconfig, but I'm not 100%. The error just disappeared.
After the error cleared down, the console highlighted many 'AOT' incompatibility errors from within my library. Which is reassuring because I didn't want to fix these blindly and also means that AOT compatibility errors are not linked with this particular error as such.
However... :stuck_out_tongue:
I am now getting this error in the console :
Uncaught ReferenceError: commonlibrary is not defined at main.js:4
I amended my rollup external globals, as well as adding "egresscommon/*": ["./node_modules/egresscommon/*"]
to my tsconfig paths, but unfortunately the issue persists.
Any ideas team? I can always create a new issue if you feel this one should now be closed?
What is on line 4 of main.js? ***Note... I am not using "paths": {... in tsconfig or anywhere else because I am using an internal npm repository. I don't know, but maybe this helps you: https://www.npmjs.com/package/sinopia
@broweratcognitecdotcom I will have a look into Sinopia, however I think we will stick with the current VSTS setup to keep everything in one place.
Here's main.js. It's actually pointing to the app.module.ngfactory:
I believe it's falling over on this line of the app,module.ngfactory:
import * as i14 from 'commonlibrary';
Which is created from the following line in my app.module:
import {CommonLibraryModule} from 'commonlibrary';
In the App's Package.json, do you declare your library module as devDependency / peerDependency?
Just in "dependencies": [] in my app's package.json. i am convinced that your lib and your app are being built using different physical @angular/core files.
In your lib's package.json AND .src/package.json make sure you have these at a minimum in your peerDeps:
"peerDependencies": { "@angular/core": "4.1.3", "rxjs": "5.1.0", "zone.js": "0.8.4", }
Your app and lib ~must~ import the same physical files from @angular/core, where NgModule is defined. I know this stuff is tricky and will cause you to lose 2 weeks and some hair, but once you get it working, you'll be golden.
my main.ts just in case it helps:
import { enableProdMode, LOCALE_ID } from '@ angular/core'; import { platformBrowserDynamic } from '@ angular/platform-browser-dynamic';
import { AppModule } from './app/app.module'; import { environment } from './environments/environment';
if (environment.production) { enableProdMode(); }
let userLang = window.navigator.language.split('-')[0];
userLang = /(de|en)/gi.test(userLang) ? userLang : 'en';
platformBrowserDynamic([{provide: LOCALE_ID, useValue: userLang}]).bootstrapModule(AppModule, {providers: [{provide: LOCALE_ID, useValue: userLang}]});
You're using a module factory. I don't know anything about that. Can you explain why? you can find me here: https://gitter.im/angular/angular. I'll give you some realtime help if you need it.
@broweratcognitecdotcom I'm running the app in AOT mode (or trying to). Maybe this does make a difference to how the library is consumed, I'm not sure. Here's a bit more info on bootstrapping with AOT compilation: https://angular.io/guide/aot-compiler#bootstrap
My end goal is to build the application with a library and be able to run it in both AOT/JIT mode.
Compiling in JIT mode I get the following:
GET http://localhost:3000/node_modules/commonlibrary/ 404 (Not Found)
which confirms it is definitely broken...
Can you show me your app module factory? btw, I am in here: https://gitter.im/angular/angular
I've resolved my issues by updating to angular-cli which seems to be working a lot better than the standalone Angular 4.0.0 build I had before.
@Davy-F — Thank you for the update! 👍
This one is racking my brains. I've searched and been through every solution on Google and GitHub, but to no avail.
Getting the following error when trying to run a new project which is consuming my library:
I believe my library is statically-analyzable for aot, and I also ran ngc --aot=false just to make sure, but I still get the error.
Here's my library CommonLibraryModule - index.ts:
And here's my AppModule:
I'm hoping I've missed something really obvious. I feel like I'm so close but falling at the last hurdle.
With the error stating "Calling function 'CommonModule'", does this mean that the error is within the CommonModule index.ts? Or could it be a probably within one of the components declared?
I know this is more of a problem with my code than the library generator, but any help would be massively appreciated.