dependency-check-team / dependency-check

checks which modules you have used in your code and then makes sure they are listed as dependencies in your package.json
https://npmjs.org/dependency-check
545 stars 38 forks source link

SyntaxError: Unexpected token (23:2) #16

Closed wayneashleyberry closed 7 years ago

wayneashleyberry commented 9 years ago

Just installed dependency check and tried it out on a project, got this error:

❯ dependency-check ./package.json         
/usr/local/lib/node_modules/dependency-check/node_modules/detective/node_modules/acorn/acorn.js:321
    throw err;
          ^
SyntaxError: Unexpected token (23:2)
    at raise (/usr/local/lib/node_modules/dependency-check/node_modules/detective/node_modules/acorn/acorn.js:319:15)
    at unexpected (/usr/local/lib/node_modules/dependency-check/node_modules/detective/node_modules/acorn/acorn.js:1311:5)
    at parseExprAtom (/usr/local/lib/node_modules/dependency-check/node_modules/detective/node_modules/acorn/acorn.js:2070:7)
    at parseExprSubscripts (/usr/local/lib/node_modules/dependency-check/node_modules/detective/node_modules/acorn/acorn.js:1933:28)
    at parseMaybeUnary (/usr/local/lib/node_modules/dependency-check/node_modules/detective/node_modules/acorn/acorn.js:1917:16)
    at parseExprOps (/usr/local/lib/node_modules/dependency-check/node_modules/detective/node_modules/acorn/acorn.js:1875:24)
    at parseMaybeConditional (/usr/local/lib/node_modules/dependency-check/node_modules/detective/node_modules/acorn/acorn.js:1860:16)
    at parseMaybeAssign (/usr/local/lib/node_modules/dependency-check/node_modules/detective/node_modules/acorn/acorn.js:1844:16)
    at parseExpression (/usr/local/lib/node_modules/dependency-check/node_modules/detective/node_modules/acorn/acorn.js:1830:16)
    at parseExprList (/usr/local/lib/node_modules/dependency-check/node_modules/detective/node_modules/acorn/acorn.js:2381:22)

Some debug info:

❯ dependency-check --version
2.2.0
❯ npm -v
2.5.1
❯ node -v
v0.12.0

Oh, and here's my package.json, if that helps.

{
  "name": "react-contact-manager",
  "description": "Primedia Contact Manager, built with React.",
  "version": "1.2.0",
  "author": "Wayne Ashley Berry <wayne@wearenext.co.za>",
  "browserify": {
    "transform": [
      "reactify"
    ]
  },
  "dependencies": {
    "condense-whitespace": "^1.0.0",
    "cookies-js": "^1.1.0",
    "debug": "^2.1.1",
    "flux": "^2.0.1",
    "honorific": "^1.0.0",
    "lodash.debounce": "^3.0.0",
    "moment": "^2.8.4",
    "months": "^1.0.0",
    "object-assign": "^2.0.0",
    "primedia-person-name": "^1.1.2",
    "primedia-search-args": "^1.0.1",
    "promise": "^6.0.1",
    "qs": "^2.3.3",
    "react": "^0.12.1",
    "react-document-title": "^0.1.3",
    "react-router": "^0.11.6",
    "superagent": "^0.21.0"
  },
  "devDependencies": {
    "browserify": "^8.1.1",
    "clean-css": "^3.0.10",
    "esprima-fb": "^10001.1.0-dev-harmony-fb",
    "jscs": "^1.11.0",
    "jsxhint": "^0.9.0",
    "parallelshell": "^1.0.0",
    "react-tools": "^0.12.1",
    "reactify": "^1.0.0",
    "superstatic": "^2.0.2",
    "uglify-js": "^2.4.16",
    "watchify": "^2.3.0"
  },
  "main": "src/bootstrap.js",
  "repository": {
    "type": "git",
    "url": "https://github.com/we-are-next/react-contact-manager.git"
  },
  "scripts": {
    "build": "browserify src/bootstrap.js -o src/bundle.js",
    "clean": "rm -f src/bundle.js",
    "css": "cleancss src/style.css -o src/style.min.css",
    "dist": "npm run build && npm run minify && npm run css",
    "http-server": "superstatic ./src -c '{\"routes\": { \"**\": \"index.html\" } }'",
    "minify": "uglifyjs src/bundle.js -o src/bundle.min.js -m -c --screw-ie8 --stats",
    "prebuild": "npm run clean",
    "prestart": "npm run build",
    "start": "parallelshell 'npm run http-server' 'npm run watch'",
    "test": "jscs src/app/**/* && jsxhint src/app/**/*",
    "watch": "watchify src/bootstrap.js -o src/bundle.js --debug --verbose"
  }
}
RichardLitt commented 9 years ago

Same problem.

$ dependency-check package.json
/usr/local/lib/node_modules/dependency-check/node_modules/detective/node_modules/acorn/acorn.js:321
    throw err;
          ^
SyntaxError: Unexpected token (21:3)
    at raise (/usr/local/lib/node_modules/dependency-check/node_modules/detective/node_modules/acorn/acorn.js:319:15)
    at unexpected (/usr/local/lib/node_modules/dependency-check/node_modules/detective/node_modules/acorn/acorn.js:1311:5)
    at parseExprAtom (/usr/local/lib/node_modules/dependency-check/node_modules/detective/node_modules/acorn/acorn.js:2070:7)
    at parseExprSubscripts (/usr/local/lib/node_modules/dependency-check/node_modules/detective/node_modules/acorn/acorn.js:1933:28)
    at parseMaybeUnary (/usr/local/lib/node_modules/dependency-check/node_modules/detective/node_modules/acorn/acorn.js:1917:16)
    at parseExprOps (/usr/local/lib/node_modules/dependency-check/node_modules/detective/node_modules/acorn/acorn.js:1875:24)
    at parseMaybeConditional (/usr/local/lib/node_modules/dependency-check/node_modules/detective/node_modules/acorn/acorn.js:1860:16)
    at parseMaybeAssign (/usr/local/lib/node_modules/dependency-check/node_modules/detective/node_modules/acorn/acorn.js:1844:16)
    at parseExpression (/usr/local/lib/node_modules/dependency-check/node_modules/detective/node_modules/acorn/acorn.js:1830:16)
    at parseExprAtom (/usr/local/lib/node_modules/dependency-check/node_modules/detective/node_modules/acorn/acorn.js:2008:17)
max-mapper commented 9 years ago

hmm im not sure how to debug in this case. I think it would need to be a trial and error thing with the source code in question. @substack any tips on debugging detective?

voxpelli commented 9 years ago

Seems like detective is using a five releases old version of acorn which in turn seems to have a problem parsing the code of the projects you are running dependecy-check on and thus fails when it tries to traverse all of the files to find all of the requires() within the project.

Since acorn seems to be to blame for this error it could be solve by detective upgrading to the latest version of acorn – which eg. this PR in the project requests: https://github.com/substack/node-detective/pull/41

voxpelli commented 9 years ago

As the PR I mentioned has now been merged and a detective version with an up to date acorn dependency has been released as 4.0.1 it would be great if you could update your dependency-check and check if the reported error still remains.

RichardLitt commented 9 years ago

I ran npm i -g dependency-check and then tried to use it, and got this:

/Users/richard/.nvm/versions/node/v0.12.0/lib/node_modules/dependency-check/node_modules/detective/node_modules/acorn/dist/acorn.js:1011
  throw err;
        ^
SyntaxError: Unexpected token (25:3)
    at Parser.pp.raise (/Users/richard/.nvm/versions/node/v0.12.0/lib/node_modules/dependency-check/node_modules/detective/node_modules/acorn/dist/acorn.js:1009:13)
    at Parser.pp.unexpected (/Users/richard/.nvm/versions/node/v0.12.0/lib/node_modules/dependency-check/node_modules/detective/node_modules/acorn/dist/acorn.js:1496:8)
    at Parser.pp.parseExprAtom (/Users/richard/.nvm/versions/node/v0.12.0/lib/node_modules/dependency-check/node_modules/detective/node_modules/acorn/dist/acorn.js:426:12)
    at Parser.pp.parseExprSubscripts (/Users/richard/.nvm/versions/node/v0.12.0/lib/node_modules/dependency-check/node_modules/detective/node_modules/acorn/dist/acorn.js:321:19)
    at Parser.pp.parseMaybeUnary (/Users/richard/.nvm/versions/node/v0.12.0/lib/node_modules/dependency-check/node_modules/detective/node_modules/acorn/dist/acorn.js:303:19)
    at Parser.pp.parseExprOps (/Users/richard/.nvm/versions/node/v0.12.0/lib/node_modules/dependency-check/node_modules/detective/node_modules/acorn/dist/acorn.js:259:19)
    at Parser.pp.parseMaybeConditional (/Users/richard/.nvm/versions/node/v0.12.0/lib/node_modules/dependency-check/node_modules/detective/node_modules/acorn/dist/acorn.js:242:19)
    at Parser.pp.parseMaybeAssign (/Users/richard/.nvm/versions/node/v0.12.0/lib/node_modules/dependency-check/node_modules/detective/node_modules/acorn/dist/acorn.js:222:19)
    at Parser.pp.parseParenAndDistinguishExpression (/Users/richard/.nvm/versions/node/v0.12.0/lib/node_modules/dependency-check/node_modules/detective/node_modules/acorn/dist/acorn.js:471:28)
    at Parser.pp.parseExprAtom (/Users/richard/.nvm/versions/node/v0.12.0/lib/node_modules/dependency-check/node_modules/detective/node_modules/acorn/dist/acorn.js:396:19)

Seems to be the same problem?

jedireza commented 9 years ago

I had a similar error.

SyntaxError: Unexpected token (41:12)
    at Parser.pp.raise (/Users/jedireza/projects/dependency-check/node_modules/detective/node_modules/acorn/dist/acorn.js:1042:13)
# ...

I console.logged some details from inside the pp.raise function of my local node_modules/detective/node_modules/acorn/dist/acorn.js file. Specifically the this.input value and the current arguments.

In my case it was a .jsx file that got picked up. And of course, the syntax wouldn't be parseable by acorn without being transformed first.

voxpelli commented 7 years ago

As it looks like this issue is caused by a JSX-file or a similar non-standard syntax that's being parsed, I'm will close this now that #61 has been merged and released.

One can now use an alternative detective/parser, such as https://github.com/dependents/node-precinct which amongst other things supports jsx.