Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crumble forces newest version of angular #9

Closed
snebjorn opened this issue Mar 19, 2018 · 5 comments
Closed

crumble forces newest version of angular #9

snebjorn opened this issue Mar 19, 2018 · 5 comments

Comments

@snebjorn
Copy link
Contributor

I get this error when installing angular-crumble

Uncaught TypeError: angular.module(...).info is not a function
at angular-route.js:58
at Object.ERR_NO_ROUTE (angular-route.js:1224)
at webpack_require (bootstrap bce38fd556aff15e6609:712)
at fn (bootstrap bce38fd556aff15e6609:117)
at Object. (index.js:1)
at webpack_require (bootstrap bce38fd556aff15e6609:712)
at fn (bootstrap bce38fd556aff15e6609:117)
at Object. (index.js:5)
at webpack_require (bootstrap bce38fd556aff15e6609:712)
at fn (bootstrap bce38fd556aff15e6609:117)

That basically mean that I have a version mismatch.
It's saying that angular-route isn't the same version as angular.

I have these packages installed:

"dependencies": {
        "angular": "1.4.5",
        "angular-crumble": "^0.2.3",
        "angular-route": "1.4.5"
}

I found a solution.

In your index.js you have

/* eslint-env node */
'use strict';

// Shim for usage with npm/browserify instead of bower
require('angular-route');
require('./crumble');
module.exports = 'crumble';

which makes sense because you have

package.json

"dependencies": {
    "angular-route": "^1.2"
  },

However that is the root cause of my problem. As I now don't have control over what version of ngRoute is used in your module.

The fix is to remove require('angular-route');

/* eslint-env node */
'use strict';

// Shim for usage with npm/browserify instead of bower
require('./crumble');
module.exports = 'crumble';

It now works :)

I'm no package.json guru. But shouldn't "angular-route" be moved to peer-dependencies in your package.json file?

Peer Dependencies
What we need is a way of expressing these "dependencies" between plugins and their host package. Some way of saying, "I only work when plugged in to version 1.2.x of my host package, so if you install me, be sure that it's alongside a compatible host." We call this relationship a peer dependency.

@raphinesse
Copy link
Owner

First of all: thanks a lot for this detailed issue and the accompanying PR.

Unfortunately, I cannot reproduce the behavior described in the issue when using this package.json. I always end up with the requested versions of angular and angular-route. Could you please report what happens when you run npm test with the package.json linked above?

Only if I omit the dependency to angular-route, crumble's dependency on angular-route@^1.2 will force the latest version of that module. The usefulness of this behavior is questionable but intended.

Your conflict might be caused by a package-lock.json. To see if that's the case, you could try a clean install (i.e. remove node_modules/ and package-lock.json before installing).

Please understand that I would rather not change something that is not actually broken, so as to not break any existing installations out there.

@snebjorn
Copy link
Contributor Author

snebjorn commented Mar 19, 2018

Found the issue. I'm using YARN which doesn't behave the same way as NPM when it comes to child dependencies. I tried doing a clean install of your example via NPM and YARN

> npm i
> npm list
[email protected]
+-- [email protected]
+-- [email protected]
| `-- [email protected] deduped
`-- [email protected]

> yarn
> yarn list
yarn list v1.5.1
├─ [email protected]
│ ├─ angular-route@^1.2
│ └─ [email protected]
├─ [email protected]
└─ [email protected]

Notice that yarn says [email protected]

Perhaps the behavior your expecting is an undocumented feature of package.json. Or there's a bug in YARN :)

@snebjorn
Copy link
Contributor Author

Workaround

Open yarn.lock and find angular-route@^1.2 and then change version and resolved to their correct values.

In my case it was:

angular-route@^1.2:
  version "1.4.5"
  resolved "https://registry.yarnpkg.com/angular-route/-/angular-route-1.4.5.tgz#59c86e30b8f7771eccc3ea3f7e8c515d5495c3ca"

@raphinesse
Copy link
Owner

Thanks again for the great debugging work!

I have given this some more thought. Whether the bad deduping in yarn is considered a bug or not, it is probably a bad idea to rely on the deduping of the package manager for correct behavior of crumble. And that means the direct dependency has to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants