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)
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!)
I just tried with the latest build, I am still getting this error.
"latest build" being @next? Or the beta? The fix is still only in @next and hasn't shipped in a tagged release yet.
Sorry I was not very specific. I took the @next. Precise build number is 3.7.0-dev.20191018.
Same as @ppn2, but downgrading to 3.7.0-dev.20191017 let me compile without this error.
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 ?
Yeah, that stack trace is entirely different.
Most helpful comment
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 whenesModuleInteropis on (as the target may end up being the module itself!)