Skip to content
This repository has been archived by the owner on Jan 5, 2024. It is now read-only.

How to track down and fix circular dependency detected error? #661

Open
ejmurra opened this issue Aug 11, 2016 · 3 comments
Open

How to track down and fix circular dependency detected error? #661

ejmurra opened this issue Aug 11, 2016 · 3 comments

Comments

@ejmurra
Copy link

ejmurra commented Aug 11, 2016

I have a project that is broken into two parts - a "core" package and a CLI that uses the core. Both are authored in Typescript.

While trying to install the core typings for use in the CLI with typings install npm:lede I have been battling a circular dependency error:

typings ERR! message Circular dependency detected using "/Users/emurray/projects/lede-cli/node_modules/babel-register/package.json"

typings ERR! cwd /Users/emurray/projects/lede-cli
typings ERR! system Darwin 14.5.0
typings ERR! command "/Users/emurray/.nvm/versions/node/v6.3.0/bin/node" "/Users/emurray/.nvm/versions/node/v6.3.0/bin/typings" "install" "npm:lede"
typings ERR! node -v v6.3.0
typings ERR! typings -v 1.3.2

My "core" package is dependent on the following:

"dependencies": {
    "archieml": "^0.3.1",
    "aws-sdk": "^2.4.11",
    "babel-preset-es2015": "^6.9.0",
    "babelify": "^7.3.0",
    "browserify": "^13.0.1",
    "fs-extra": "^0.30.0",
    "glob": "^7.0.3",
    "livereload": "^0.4.1",
    "lodash": "^4.4.0",
    "node-sass": "^3.7.0",
    "nunjucks": "^2.4.2",
    "rimraf": "^2.5.2"
  },
  "devDependencies": {
    "ava": "^0.15.2",
    "coveralls": "^2.11.11",
    "nyc": "^7.0.0",
    "typescript": "^1.8.10",
    "typings": "^1.3.2"
  }

In my best effort to figure out what was going on, I added the high-tech debug statements

console.log("Source: " + src)
console.log("Parent: " + JSON.stringify(parent, null, 2))

just above this line in the typings-core source and then reran the command and piped stdout to a file.

The majority of that file is unimportant but the important bit is here at the end:

Source: /Users/emurray/projects/lede-cli/node_modules/babel-core/package.json
Parent: {
  "src": "/Users/emurray/projects/lede-cli/node_modules/babel-register/package.json",
  "raw": "npm:babel-register",
  "main": "lib/node.js",
  "browser": "lib/browser.js",
  "version": "6.11.6",
  "global": false,
  "dependencies": {},
  "devDependencies": {},
  "peerDependencies": {},
  "globalDependencies": {},
  "globalDevDependencies": {},
  "name": "babel-register",
  "parent": {
    "src": "/Users/emurray/projects/lede-cli/node_modules/babel-core/package.json",
    "raw": "npm:babel-core",
    "version": "6.13.2",
    "global": false,
    "dependencies": {},
    "devDependencies": {},
    "peerDependencies": {},
    "globalDependencies": {},
    "globalDevDependencies": {},
    "name": "babel-core",
    "parent": {
      "src": "/Users/emurray/projects/lede-cli/node_modules/babelify/package.json",
      "raw": "npm:babelify",
      "version": "7.3.0",
      "global": false,
      "dependencies": {},
      "devDependencies": {},
      "peerDependencies": {},
      "globalDependencies": {},
      "globalDevDependencies": {},
      "name": "babelify",
      "parent": {
        "src": "/Users/emurray/projects/lede-cli/node_modules/lede/package.json",
        "raw": "npm:lede",
        "main": "dist/index.js",
        "typings": "dist/index.d.ts",
        "version": "0.0.13",
        "global": false,
        "dependencies": {},
        "devDependencies": {},
        "peerDependencies": {},
        "globalDependencies": {},
        "globalDevDependencies": {},
        "name": "lede"
      }
    }
  }
}

So it seems to me that I am depending on a package (babelify) that depends on babel-core which depends on babel-register, which in turn depends on babel-core - thus the circular dependency! However I find it curious that this circular dependency isn't thrown by npm itself and it has me wondering if typings isn't resolving this as it should be or if I have just royally messed something up.

@ejmurra ejmurra changed the title How to track down circular dependency detected error? How to track down and fix circular dependency detected error? Aug 11, 2016
@blakeembrey
Copy link
Member

blakeembrey commented Aug 12, 2016

I think this might have been fixed in NPM v3 with flattening, but might not work in v2. That said, this behaviour in Typings may be able to be improved so that during resolution it can reference the parent type and during compilation it re-uses previous paths.

@bsouthga
Copy link

I get the same issue on with npm@3.10.3, node@6.3.1, typings@1.3.2, darwin@15.6.0

@blakeembrey
Copy link
Member

Anyone is welcome to submit a PR, I haven't had time to fix it. It's be a matter of re-using the pointer during dependencies.ts and then checking for pointers during compile.ts in typings-core.

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

No branches or pull requests

3 participants