Skip to content

Crash in getJSDocTags on const a = b = () => 0; #24963

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

Closed
ghost opened this issue Jun 14, 2018 · 30 comments · Fixed by #24973
Closed

Crash in getJSDocTags on const a = b = () => 0; #24963

ghost opened this issue Jun 14, 2018 · 30 comments · Fixed by #24973
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@ghost
Copy link

ghost commented Jun 14, 2018

TypeScript Version: 3.0.0-dev.20180609

Code

a.js

/** doc */
const a = b = () => 0;

Expected behavior:

No crash.

Actual behavior:

Error: Debug Failure. False expression.
    at getJSDocTags (/home/andy/.nvm/versions/node/v10.1.0/lib/node_modules/typescript/lib/tsc.js:10444:22)
    at getFirstJSDocTag (/home/andy/.nvm/versions/node/v10.1.0/lib/node_modules/typescript/lib/tsc.js:10451:24)
    at Object.getJSDocType (/home/andy/.nvm/versions/node/v10.1.0/lib/node_modules/typescript/lib/tsc.js:10428:19)
    at getContextualSignature (/home/andy/.nvm/versions/node/v10.1.0/lib/node_modules/typescript/lib/tsc.js:34131:32)
    at checkFunctionExpressionOrObjectLiteralMethod (/home/andy/.nvm/versions/node/v10.1.0/lib/node_modules/typescript/lib/tsc.js:36920:43)
    at checkExpressionWorker (/home/andy/.nvm/versions/node/v10.1.0/lib/node_modules/typescript/lib/tsc.js:37846:28)
    at checkExpression (/home/andy/.nvm/versions/node/v10.1.0/lib/node_modules/typescript/lib/tsc.js:37779:42)
    at checkBinaryLikeExpression (/home/andy/.nvm/versions/node/v10.1.0/lib/node_modules/typescript/lib/tsc.js:37393:29)
    at checkBinaryExpression (/home/andy/.nvm/versions/node/v10.1.0/lib/node_modules/typescript/lib/tsc.js:37385:20)
    at checkExpressionWorker (/home/andy/.nvm/versions/node/v10.1.0/lib/node_modules/typescript/lib/tsc.js:37867:28)

CC @sandersn

@mhegazy mhegazy added the Bug A bug in TypeScript label Jun 14, 2018
@mhegazy mhegazy added this to the TypeScript 3.0 milestone Jun 14, 2018
@mhegazy
Copy link
Contributor

mhegazy commented Jun 14, 2018

@sandersn can you take a look.

@sandersn
Copy link
Member

The assert is the one that detects duplicated jsdoc tags. () => 0 is getting doc added twice.

@MLoughry
Copy link

Is there any plan to release a 2.9.3 with this fix?

@larssn
Copy link

larssn commented Aug 8, 2018

Pretty please?

@RyanCavanaugh
Copy link
Member

TypeScript 3.0 is out, which contains a fix for this issue and doesn't have any major breaking changes associated with it. I'd recommend upgrading to that version as we don't plan to backport a new 2.9 release at this time.

@larssn
Copy link

larssn commented Aug 9, 2018

Thanks Ryan, we're stuck using 2.9.2 due to Angular 6 though. Thanks anyway.

@rodrigoEclipsa
Copy link

rodrigoEclipsa commented Aug 10, 2018

I'm also with angular 6, can we solve it in some way?

@ghost
Copy link
Author

ghost commented Aug 14, 2018

@rodrigoEclipsa Try looking for double assignments a = b = c in your program and breaking them up to b = c; a = b;.

@ClemensSchneider
Copy link

ClemensSchneider commented Sep 14, 2018

Just in the progress of upgrading from Angular 5 to 6 and stumbled upon this issue, too. As there aren't any plans for Angular 6 to be upgraded to TypeScript 3 and there aren't any plans to backport this fix to the TypeScript 2.9 branch it seems that there isn't any chance to upgrade to Angular 6 :(

More detailed: Having a dependency on autobahn.js which depends on crypto-js which causes this issue.

@mrowles
Copy link

mrowles commented Oct 15, 2018

Does anyone have a fix for angular@6 yet? I don't have any double assignments, it's referencingcrypto-js@^3.1.9-1 for me (a dependency of amazon-cognito-identity-js).

@stormit-vn
Copy link

I am facing this issue too, waiting for resolutions

@sandersn
Copy link
Member

It's probably easiest to fix crypto-js since that's the library everybody on this thread depends on.

@sandersn
Copy link
Member

Actually, I wonder why crypto-js is being checked. If it has a d.ts file, then it should never check the JS file at all. For future investigation:

  1. Do you have allowJs on?
  2. Do you have @types/crypto-js installed?

@mrowles
Copy link

mrowles commented Oct 15, 2018

I agree, it’s weird. It also fails with @types/crypto-js installed, but have not tried allowJs yet, will check in a minute

@mrowles
Copy link

mrowles commented Oct 16, 2018

@sandersn allowJS true/false makes no difference. I've tried a number of combinations.

My specific problem, and I'd garner a bet that this would be most peoples, it appears that it's the AWS Cognito suite that is using this library. aws-amplify, which uses another library amazon-cognito-identity-js that utilizes crypto-js.

@stormit-vn
Copy link

stormit-vn commented Oct 16, 2018

I got the same error when trying to use aws-amplify. Hope we can find out a solution to fix this issue soon.

I am trying the latest angular version v7.x bit this issue still not be fixed

@sandersn
Copy link
Member

@stormit-vn Does angular 7 still use typescript 2.9?

@mrowles @stormit-vn I modified crypto-js. Can you try installing from my branch to see if it works? I think this is the command: npm install git://github.com/sandersn/crypto-js.git#typescript-2.9-workaround.

@d2kx
Copy link

d2kx commented Oct 17, 2018

@sandersn Angular 7 is targeting TypeScript 3.1.3, but is not released yet (currently in release candidate stage). Haven't checked if it fixes the issue, but am probably going to, because I also suffer from this issue with my Angular 6 + AWS Amplify app (crypto-js dep.).

Someone over at #25067 (comment) seems to still have the issue with TypeScript 3.1, so I am not too hopeful.

@mrowles
Copy link

mrowles commented Oct 17, 2018

@sandersn Thanks for your efforts mate, very much appreciated. Unfortunately this didn't seem to work in my project, with various configs. Perhaps I need to fork and update amazon-cognito-identity-js? Errors below :)

Normal build/non-AOT (previously working, now broken, new errors):

ERROR in ./node_modules/amazon-cognito-identity-js/es/AuthenticationHelper.js
Module not found: Error: Can't resolve 'crypto-js' in '/Users/username/workspace/project/node_modules/amazon-cognito-identity-js/es'
 @ ./node_modules/amazon-cognito-identity-js/es/AuthenticationHelper.js 21:0-38 24:21-33 221:38-50 222:18-33 249:28-40 250:47-59 251:49-61 253:14-33 254:15-34
 @ ./node_modules/amazon-cognito-identity-js/es/index.js
 @ ./node_modules/@aws-amplify/auth/lib/index.js
 @ ./node_modules/aws-amplify/lib/index.js
 @ ./src/app/auth/auth.service.ts
 @ ./src/app/app.module.ts
 @ ./src/app/index.ts
 @ ./src/main.browser.ts
 @ multi (webpack)-dev-server/client?http://localhost:5000 ./src/main.browser.ts

ERROR in ./node_modules/amazon-cognito-identity-js/es/CognitoUser.js
Module not found: Error: Can't resolve 'crypto-js' in '/Users/username/workspace/project/node_modules/amazon-cognito-identity-js/es'
 @ ./node_modules/amazon-cognito-identity-js/es/CognitoUser.js 21:0-38 299:24-36 300:20-32 301:32-44 301:62-81 621:24-36 622:20-32 623:32-44 623:62-81
 @ ./node_modules/amazon-cognito-identity-js/es/index.js
 @ ./node_modules/@aws-amplify/auth/lib/index.js
 @ ./node_modules/aws-amplify/lib/index.js
 @ ./src/app/auth/auth.service.ts
 @ ./src/app/app.module.ts
 @ ./src/app/index.ts
 @ ./src/main.browser.ts
 @ multi (webpack)-dev-server/client?http://localhost:5000 ./src/main.browser.ts

AOT Build (previously broken, still broken, but new errors):

70% building modules 1178/1178 modules 0 activeModuleNotFoundError: Module not found: Error: Can't resolve 'crypto-js' in '/Users/username/workspace/project/node_modules/amazon-cognito-identity-js/es'
    at factory.create (/Users/username/workspace/project/node_modules/webpack/lib/Compilation.js:547:10)
    at factory (/Users/username/workspace/project/node_modules/webpack/lib/NormalModuleFactory.js:397:22)
    at resolver (/Users/username/workspace/project/node_modules/webpack/lib/NormalModuleFactory.js:130:21)
    at asyncLib.parallel (/Users/username/workspace/project/node_modules/webpack/lib/NormalModuleFactory.js:224:22)
    at /Users/username/workspace/project/node_modules/neo-async/async.js:2772:7
    at /Users/username/workspace/project/node_modules/neo-async/async.js:6730:13
    at normalResolver.resolve (/Users/username/workspace/project/node_modules/webpack/lib/NormalModuleFactory.js:214:25)
    at doResolve (/Users/username/workspace/project/node_modules/enhanced-resolve/lib/Resolver.js:184:12)
    at hook.callAsync (/Users/username/workspace/project/node_modules/enhanced-resolve/lib/Resolver.js:238:5)
    at _fn0 (eval at create (/Users/username/workspace/project/node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:15:1)
    at resolver.doResolve (/Users/username/workspace/project/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js:37:5)
    at hook.callAsync (/Users/username/workspace/project/node_modules/enhanced-resolve/lib/Resolver.js:238:5)
    at _fn0 (eval at create (/Users/username/workspace/project/node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:15:1)
    at hook.callAsync (/Users/username/workspace/project/node_modules/enhanced-resolve/lib/Resolver.js:238:5)
    at _fn0 (eval at create (/Users/username/workspace/project/node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:12:1)
    at resolver.doResolve (/Users/username/workspace/project/node_modules/enhanced-resolve/lib/DescriptionFilePlugin.js:42:38)
    at hook.callAsync (/Users/username/workspace/project/node_modules/enhanced-resolve/lib/Resolver.js:238:5)
    at _fn40 (eval at create (/Users/username/workspace/project/node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:372:1)
    at resolver.doResolve (/Users/username/workspace/project/node_modules/enhanced-resolve/lib/ModuleKindPlugin.js:23:37)
    at hook.callAsync (/Users/username/workspace/project/node_modules/enhanced-resolve/lib/Resolver.js:238:5)
    at _fn0 (eval at create (/Users/username/workspace/project/node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:15:1)
    at hook.callAsync (/Users/username/workspace/project/node_modules/enhanced-resolve/lib/Resolver.js:238:5)
    at _fn1 (eval at create (/Users/username/workspace/project/node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:24:1)
    at hook.callAsync (/Users/username/workspace/project/node_modules/enhanced-resolve/lib/Resolver.js:238:5)
    at _fn0 (eval at create (/Users/username/workspace/project/node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:15:1)
    at resolver.doResolve (/Users/username/workspace/project/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js:37:5)
    at hook.callAsync (/Users/username/workspace/project/node_modules/enhanced-resolve/lib/Resolver.js:238:5)
    at _fn0 (eval at create (/Users/username/workspace/project/node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:15:1)
    at hook.callAsync (/Users/username/workspace/project/node_modules/enhanced-resolve/lib/Resolver.js:238:5)
    at _fn0 (eval at create (/Users/username/workspace/project/node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:12:1)
    at resolver.doResolve (/Users/username/workspace/project/node_modules/enhanced-resolve/lib/DescriptionFilePlugin.js:42:38)
    at hook.callAsync (/Users/username/workspace/project/node_modules/enhanced-resolve/lib/Resolver.js:238:5)
    at _fn41 (eval at create (/Users/username/workspace/project/node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:384:1)
    at hook.callAsync (/Users/username/workspace/project/node_modules/enhanced-resolve/lib/Resolver.js:238:5)
    at _fn0 (eval at create (/Users/username/workspace/project/node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:12:1)
    at resolver.doResolve (/Users/username/workspace/project/node_modules/enhanced-resolve/lib/DescriptionFilePlugin.js:42:38)
resolve 'crypto-js' in '/Users/username/workspace/project/node_modules/amazon-cognito-identity-js/es'
  Parsed request is a module
  using description file: /Users/username/workspace/project/node_modules/amazon-cognito-identity-js/package.json (relative path: ./es)
    Field 'browser' doesn't contain a valid alias configuration
    resolve as module
      looking for modules in /Users/username/workspace/project/src
        using description file: /Users/username/workspace/project/package.json (relative path: ./src)
          Field 'browser' doesn't contain a valid alias configuration
          using description file: /Users/username/workspace/project/package.json (relative path: ./src/crypto-js)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              /Users/username/workspace/project/src/crypto-js doesn't exist
            .mjs
              Field 'browser' doesn't contain a valid alias configuration
              /Users/username/workspace/project/src/crypto-js.mjs doesn't exist
            .ts
              Field 'browser' doesn't contain a valid alias configuration
              /Users/username/workspace/project/src/crypto-js.ts doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              /Users/username/workspace/project/src/crypto-js.js doesn't exist
            .json
              Field 'browser' doesn't contain a valid alias configuration
              /Users/username/workspace/project/src/crypto-js.json doesn't exist
            as directory
              /Users/username/workspace/project/src/crypto-js doesn't exist
      looking for modules in /Users/username/workspace/project/node_modules
        using description file: /Users/username/workspace/project/package.json (relative path: ./node_modules)
          Field 'browser' doesn't contain a valid alias configuration
          using description file: /Users/username/workspace/project/node_modules/crypto-js/package.json (relative path: .)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              /Users/username/workspace/project/node_modules/crypto-js is not a file
            .mjs
              Field 'browser' doesn't contain a valid alias configuration
              /Users/username/workspace/project/node_modules/crypto-js.mjs doesn't exist
            .ts
              Field 'browser' doesn't contain a valid alias configuration
              /Users/username/workspace/project/node_modules/crypto-js.ts doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              /Users/username/workspace/project/node_modules/crypto-js.js doesn't exist
            .json
              Field 'browser' doesn't contain a valid alias configuration
              /Users/username/workspace/project/node_modules/crypto-js.json doesn't exist
            as directory
              existing directory
                use ./index.js from main in package.json
                  using description file: /Users/username/workspace/project/node_modules/crypto-js/package.json (relative path: .)
                    Field 'browser' doesn't contain a valid alias configuration
                    using description file: /Users/username/workspace/project/node_modules/crypto-js/package.json (relative path: ./index.js)
                      no extension
                        Field 'browser' doesn't contain a valid alias configuration
                        /Users/username/workspace/project/node_modules/crypto-js/index.js doesn't exist
                      .mjs
                        Field 'browser' doesn't contain a valid alias configuration
                        /Users/username/workspace/project/node_modules/crypto-js/index.js.mjs doesn't exist
                      .ts
                        Field 'browser' doesn't contain a valid alias configuration
                        /Users/username/workspace/project/node_modules/crypto-js/index.js.ts doesn't exist
                      .js
                        Field 'browser' doesn't contain a valid alias configuration
                        /Users/username/workspace/project/node_modules/crypto-js/index.js.js doesn't exist
                      .json
                        Field 'browser' doesn't contain a valid alias configuration
                        /Users/username/workspace/project/node_modules/crypto-js/index.js.json doesn't exist
                      as directory
                        /Users/username/workspace/project/node_modules/crypto-js/index.js doesn't exist
                using path: /Users/username/workspace/project/node_modules/crypto-js/index
                  using description file: /Users/username/workspace/project/node_modules/crypto-js/package.json (relative path: ./index)
                    no extension
                      Field 'browser' doesn't contain a valid alias configuration
                      /Users/username/workspace/project/node_modules/crypto-js/index doesn't exist
                    .mjs
                      Field 'browser' doesn't contain a valid alias configuration
                      /Users/username/workspace/project/node_modules/crypto-js/index.mjs doesn't exist
                    .ts
                      Field 'browser' doesn't contain a valid alias configuration
                      /Users/username/workspace/project/node_modules/crypto-js/index.ts doesn't exist
                    .js
                      Field 'browser' doesn't contain a valid alias configuration
                      /Users/username/workspace/project/node_modules/crypto-js/index.js doesn't exist
                    .json
                      Field 'browser' doesn't contain a valid alias configuration
                      /Users/username/workspace/project/node_modules/crypto-js/index.json doesn't exist
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] webpack: `node --max_old_space_size=4096 node_modules/webpack/bin/webpack.js "--config" "config/webpack.prod.js" "--mode" "production" "--progress" "--profile" "--bail"`
npm ERR! Exit status 1

I found the webpack.config extension property references interesting here:

Field 'browser' doesn't contain a valid alias configuration
              /Users/username/workspace/project/node_modules/crypto-js is not a file
            .mjs | ts | js | json etc.

I believe angular@7 removes the <2.10 dependency.

@sandersn
Copy link
Member

@mrowles Can you try something like

$ cd node_modules/crypto-js
$ npm install
$ npm run build     # I needed to install grunt first

I suspect that the version installed from github doesn't have files in the right places.

It's also possible that 3.1.9-1 didn't get installed in the top-level node_modules, but underneath amazon-cognito-identity, and that the github-installed version isn't being resolved at all.

@d2kx
Copy link

d2kx commented Oct 17, 2018

FWIW, I did a very brief test with a straight-forward upgrade to Angular 7.0.0-rc.1, Angular CLI 7.0.0-rc.3 and TypeScript 3.1.x with an AWS-Amplify/crypto-js project that failed before and it actually works now.

@mrowles
Copy link

mrowles commented Oct 18, 2018

Wonder what is different? I upgraded to the following and still no luck, exactly the same errors (even after a clean npm install):

"dependencies": {
  "@angular/animations": "7.0.0-rc.1",
  "@angular/cdk": "7.0.0-rc.1",
  "@angular/common": "7.0.0-rc.1",
  "@angular/compiler": "7.0.0-rc.1",
  "@angular/core": "7.0.0-rc.1",
  "@angular/forms": "7.0.0-rc.1",
  "@angular/platform-browser": "7.0.0-rc.1",
  "@angular/platform-browser-dynamic": "7.0.0-rc.1",
  "@angular/platform-server": "7.0.0-rc.1",
  "@angular/router": "7.0.0-rc.1",
  "aws-amplify": "1.1.6",
  ...
  "crypto-js": "^3.1.9-1",
  ...
},
"devDependencies": {
  "@angular-devkit/build-angular": "0.8.5",
  "@angular-devkit/build-optimizer": "0.8.5",
  "@angular/cli": "7.0.0-rc.3 ",
  "@angular/compiler-cli": "7.0.0-rc.1",
  "@angular/language-service": "7.0.0-rc.1",
  "@types/crypto-js": "3.1.43",
  ...
  "typescript": "3.1.3",
  ...
}

I also tried to use @sandersn PR sha to no avail :(

@mrowles
Copy link

mrowles commented Oct 18, 2018

I have updated the following packages and my errors have changed, so possibly resolving the previous problems in case it works for the others:

devDependencies: {
  "@angular-devkit/build-optimizer": "0.9.0-rc.3",
  "@ngtools/webpack": "7.0.0-rc.3",
  "uglifyjs-webpack-plugin": "2.0.1",
}

My errors are now potentially related to something else:

ERROR in ./node_modules/amazon-cognito-identity-js/es/CognitoUser.js
Module build failed (from ./node_modules/@angular-devkit/build-optimizer/src/build-optimizer/webpack-loader.js):
TypeError: Cannot read property 'flags' of undefined
    at isRelatedTo (/Users/username/workspace/project/node_modules/@angular-devkit/build-optimizer/node_modules/typescript/lib/typescript.js:40600:28)

I've installed [email protected] which still didn't fix this issue, but this might be a config issue with webpack or some such, i'll keep digging.

@sandersn
Copy link
Member

Well, it’s still a crash in tsc, but in a different place. Can you run node <tsc-path-inside-angular-devkit> —version and see if or something newer?

@mrowles
Copy link

mrowles commented Oct 18, 2018

@sandersn It is using 8.9.4, so I downgraded my version to the same (from 9.x) but still no luck.

@mrowles
Copy link

mrowles commented Oct 19, 2018

With the actual release of angular@7 today, along with @ngtools/[email protected] + @angular-devkit/[email protected] - this is now working!

Big thanks to @sandersn for the help dude!

@stormit-vn
Copy link

Thank you all for your help. We now able to build the bundler.

Cheers!

@MikeAlexMartinez
Copy link

Is there a fix for this issue if you are still using Angular v6?

@JamDoughnnut
Copy link

For Angular v6 try version 3.1.2-2

@chenghongm
Copy link

following @Andy-MS comment, I manually broken down all double assignment a= b = c into a= b; b= c in these two files of ./node_modules/crypto-js/core.js and ./node_modules/crypto-js/cipher-core.js; then error gone!!

my angular version:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.