aurelia-contrib / aurelia-open-id-connect

An aurelia adapter for the IdentityModel/oidc-client-js
https://zamboni-app.azurewebsites.net
MIT License
54 stars 18 forks source link

SpaTemplate "Two different types with this name exist, but they are unrelated" #39

Closed gerbendekker closed 6 years ago

gerbendekker commented 6 years ago

Hello, I started a new project using the ASP.NET Core SpaTemplate and get this error when adding:

import { PLATFORM, autoinject } from 'aurelia-framework';
import { Router, RouterConfiguration } from 'aurelia-router';
import { OpenIdConnect, OpenIdConnectRoles } from "aurelia-open-id-connect";

@autoinject()
export class App {
    ...
    configureRouter(config: RouterConfiguration, router: Router) {
        ...
        this.openIdConnect.configure(config); //<- Two different types with this name exist, but they are unrelated
        ...
    }
}

This is because their are two versions of the Aurelia codebase.

When I remove them inside the project node_modules the issue is resolved. image

Shouldn't the 'yarn.lock' be removed from this repository?

shaunluttin commented 6 years ago

Thank you for raising this issue. I was not aware of the problem. I will take a look.

I am not sure about the inclusion of the yarn.lock file and will do some research on that too. The https://yarnpkg.com/lang/en/docs/yarn-lock/#toc-current-package-only heading says:

During install Yarn will only use the top-level yarn.lock file and will ignore any yarn.lock files that exist within dependencies. The top-level yarn.lock file includes everything Yarn needs to lock the versions of all packages in the entire dependency tree.

It might be that in our package we need to include the aurelia-router as a peer dependency... #learning

shaunluttin commented 6 years ago

How did you create the ASP.NET Core Aurelia Spa Template? In the dotnet new list, I see only React and Angular templates.

shaunluttin commented 6 years ago

Found it. We need to install the SPA templates like this first:

dotnet new --install Microsoft.AspNetCore.SpaTemplates::*

Then we can run

dotnet new aurelia

https://blogs.msdn.microsoft.com/webdev/2017/02/14/building-single-page-applications-on-asp-net-core-with-javascriptservices/

shaunluttin commented 6 years ago

So, I was not able to reproduce your error with the ASP.NET Core Aurelia SPA template, because I'm afraid I do not know how to configure Webpack. If you can provide a sample application, for instance, in a GitHub repository, that would help me a great deal.

What I did do is to ignore both the package.lock.json and the yarn.lock files in the npm publish package. Those changes are included in release 0.19.8 on NPM.

Please let me know whether using the ^0.19.8 release resolves the problem or not.

gerbendekker commented 6 years ago

I reproduced the problem in the repo: aurelia-app-identity-server-aspnetcore

0.19.8 or 0.19.9 had no effect. peerDependencies solved it. All other aurelia packages use 'dependencies', can't find the difference yet, must be missing something.

gerbendekker commented 6 years ago

"During install Yarn will only use the top-level yarn.lock file" Sound logical, but that would assume that consumers always use a root yarn.lock? They might be using none or different kind of 'lock'. As described here lockfiles-for-all, yarn everywhere is not a problem... As far I know, you could use lock files for projects but better not for libs/plugins. Probably it depends.

shaunluttin commented 6 years ago

That's great! Thank you for the fork. I turned the demo into a pull request here:

https://github.com/shaunluttin/aurelia-open-id-connect-demos/pull/1

:clap: :clap: :clap:

shaunluttin commented 6 years ago

What do you mean when you say that, "peerDependencies solved it?"

We have run the demo that you created here: https://github.com/shaunluttin/aurelia-open-id-connect-demos/tree/master/aurelia-app-identity-server-aspnetcore It seems to be working without the use of peerDependencies.

gerbendekker commented 6 years ago

Yes the demo works, but still have typings errors. Like you mentioned in the readme, a second 'dotnet build' clears the errors in the consol but they are still present.

The first bullet issue is resolved when I delete the folder 'aurelia-app-identity-server-aspnetcore\node_modules\aurelia-open-id-connect\node_modules'. When changing the 'package.json' dependencies to peerDependencies, then on the next npm install the 'node_modules' are not restored. All it showed is a warning about the 'peerDependencies'.

  },
  "peerDependencies": {
    "aurelia-fetch-client": "^1.1.3",
    "aurelia-framework": "^1.1.5",
    "aurelia-router": "^1.4.0",
    "babel-polyfill": "^6.26.0",
    "oidc-client": "^1.4.1"
  },
  "description": "An Aurelia adapter for the IdentityModel/oidc-client-js.",
  "devDependencies": {

I'm not saying it should be 'peerDependencies'. If you look at for example the 'aurelia-binding' it uses dependencies but no 'node_modules' are restored. Don't why that is different, still searching... #learning2 Maybe take a look at the structure used by ux or skeleton-plugin

shaunluttin commented 6 years ago

Thank you for that clarification.

Another data point is that the errors happen with the ASP.NET Core template demo but not with the other demos. That could be related to Webpack, ASP.NET Core, or something else that differs.

shaunluttin commented 6 years ago

This is a lead: https://docs.npmjs.com/files/folders#cycles-conflicts-and-folder-parsimony

It might be that the official aurelia packages avoid duplication by having the exact same version of their dependencies.

gerbendekker commented 6 years ago

Currently working on it here, still need to do some bug fixing. Then you can apply it based on your own preferences.

The changes so far:

shaunluttin commented 6 years ago

Thank you. I would like to make comments. Could you please turn it into a pull request. That would let me work in real time with you on it.

gerbendekker commented 6 years ago

done in #44

shaunluttin commented 6 years ago

Thank you. I will take a look. 👍