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

"Cannot read property 'declarations' of undefined" error when using React prop-types in JSX files #33735

Closed
mohsen1 opened this issue Oct 2, 2019 · 7 comments · Fixed by #33813
Assignees
Labels
Bug A bug in TypeScript Domain: Declaration Emit The issue relates to the emission of d.ts files Domain: JavaScript The issue relates to JavaScript specifically

Comments

@mohsen1
Copy link
Contributor

mohsen1 commented Oct 2, 2019

TypeScript Version: "3.7.0-dev.20191001"

Search Terms:

Code

// file.jsx
import PropTypes from 'prop-types';
import React from 'react';

const propTypes = {
  bar: PropTypes.bool,
};

const defaultProps = {
  bar: false,
};

function Foo({ bar }) {
  return <div>{bar}</div>;
}

Foo.propTypes = propTypes;
Foo.defaultProps = defaultProps;

export default Foo;

compiler options

{
  "compilerOptions": {
    "target": "es2015",
    "module": "commonjs",
    "moduleResolution": "node",
    "jsx": "react",
    "lib": ["dom", "es2017", "esnext.asynciterable"],
    "declaration": true,
    "declarationMap": true,
    "sourceMap": true,
    "composite": true,
    "esModuleInterop": true,
    "downlevelIteration": true,
    "strict": true,
    "noErrorTruncation": true,
    "resolveJsonModule": true,
    "allowSyntheticDefaultImports": true,
    "forceConsistentCasingInFileNames": true,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "noImplicitAny": true,
    "suppressImplicitAnyIndexErrors": true,
    "noUnusedLocals": false,
    "noUnusedParameters": false,
    "importHelpers": true
  },
  "exclude": ["node_modules", "projects/*/node_modules", "projects/*/lib", "projects/*/build"]
}
{
  "extends": "./tsconfig.settings.json",
  "compilerOptions": {
    "allowJs": true
  },
  "files": [
    "/path/to/file.jsx"
  ]
}

Expected behavior:
No error

Actual behavior:
Compiler crashes with:


/work/node_modules/typescript/lib/tsc.js:78403
                throw e;
                ^

TypeError: Cannot read property 'declarations' of undefined
    at getSpecifierForModuleSymbol (/work/node_modules/typescript/lib/tsc.js:30502:61)
    at serializeAsAlias (/work/node_modules/typescript/lib/tsc.js:31191:171)
    at serializeSymbolWorker (/work/node_modules/typescript/lib/tsc.js:30971:25)
    at serializeSymbol (/work/node_modules/typescript/lib/tsc.js:30923:38)
    at /work/node_modules/typescript/lib/tsc.js:30908:29
    at Map.forEach (<anonymous>)
    at visitSymbolTable (/work/node_modules/typescript/lib/tsc.js:30907:42)
    at serializeAsNamespaceDeclaration (/work/node_modules/typescript/lib/tsc.js:31132:25)
    at serializeModule (/work/node_modules/typescript/lib/tsc.js:31051:25)
    at serializeSymbolWorker (/work/node_modules/typescript/lib/tsc.js:30965:25)
@weswigham weswigham added Bug A bug in TypeScript Domain: Declaration Emit The issue relates to the emission of d.ts files Domain: JavaScript The issue relates to JavaScript specifically labels Oct 3, 2019
@weswigham weswigham self-assigned this Oct 3, 2019
@weswigham weswigham added this to the TypeScript 3.7.0 milestone Oct 3, 2019
@weswigham
Copy link
Member

Excellent and succinct repro, thanks ❤️ I'll work on a fix tomorrow - the issue seems to be that an assumption made that a import def from "foo" alias target always has a parent symbol isn't quite true when esModuleInterop is on (as the target may end up being the module itself!)

@ajayvikas
Copy link

I just tried with the latest build, I am still getting this error.

@weswigham
Copy link
Member

"latest build" being @next? Or the beta? The fix is still only in @next and hasn't shipped in a tagged release yet.

@ajayvikas
Copy link

Sorry I was not very specific. I took the @next. Precise build number is 3.7.0-dev.20191018.

@noahseger
Copy link

Same as @ppN2, but downgrading to 3.7.0-dev.20191017 let me compile without this error.

@capaj
Copy link

capaj commented Nov 20, 2020

I got this today when I updated 4.0.1 to 4.1.2 on a big project(has esModuleInterop enabled):

/home/capaj/work-repos/looop/project-alpha3/node_modules/typescript/lib/tsc.js:87001
                throw e;
                ^

TypeError: Cannot read property 'declarations' of undefined
    at addImplementationSuccessElaboration (/home/capaj/work-repos/looop/project-alpha3/node_modules/typescript/lib/tsc.js:57022:116)
    at resolveCall (/home/capaj/work-repos/looop/project-alpha3/node_modules/typescript/lib/tsc.js:56947:33)
    at resolveJsxOpeningLikeElement (/home/capaj/work-repos/looop/project-alpha3/node_modules/typescript/lib/tsc.js:57576:20)
    at resolveSignature (/home/capaj/work-repos/looop/project-alpha3/node_modules/typescript/lib/tsc.js:57597:28)
    at getResolvedSignature (/home/capaj/work-repos/looop/project-alpha3/node_modules/typescript/lib/tsc.js:57608:26)
    at checkJsxOpeningLikeElementOrOpeningFragment (/home/capaj/work-repos/looop/project-alpha3/node_modules/typescript/lib/tsc.js:55477:27)
    at checkJsxElementDeferred (/home/capaj/work-repos/looop/project-alpha3/node_modules/typescript/lib/tsc.js:55065:13)
    at checkDeferredNode (/home/capaj/work-repos/looop/project-alpha3/node_modules/typescript/lib/tsc.js:64405:21)
    at Map.forEach (<anonymous>)
    at checkDeferredNodes (/home/capaj/work-repos/looop/project-alpha3/node_modules/typescript/lib/tsc.js:64373:37)

I should probably open this as a new ticket right @weswigham ?

@weswigham
Copy link
Member

Yeah, that stack trace is entirely different.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: Declaration Emit The issue relates to the emission of d.ts files Domain: JavaScript The issue relates to JavaScript specifically
Projects
None yet
6 participants