TypeScript: BUG: `allowSyntheticDefaultImports: true` breaks Typescript auto-import

  • VSCode Version: 1.34.0
  • OS Version: OS X 10.14.4
  • Typescript Version: 3.4.5
  • Create React App: 2.1.5

tsconfig.json:

{
  "compilerOptions": {
    "target": "es6",
    "allowJs": true,
    "skipLibCheck": false,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "preserve",
    "lib": [
      "esnext",
      "dom"
    ]
  },
  "include": [
    "src"
  ]
}

Behavior when true:

true

Behavior when false:

false

We have another project that seems to work fine with allowSyntheticDefaultImports: true. The other project is an Express app and its tsconfig.json is:

{
  "compilerOptions": {
    "module": "commonjs",
    "esModuleInterop": true,
    "target": "es6",
    "strict": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "emitDecoratorMetadata": true,
    "moduleResolution": "node",
    "sourceMap": true,
    "declaration": true,
    "outDir": "dist",
    "resolveJsonModule": true,
    "baseUrl": ".",
    "paths": {
      "*": [
        "node_modules/*",
        "src/types/*"
      ]
    },
    "lib": [
      "esnext",
      "dom"
    ]
  },
  "include": [
    "src/**/*"
  ]
}

We’ve directly copied its tsconfig.json, but that doesn’t seem to bring back auto-import.

Does this issue occur when all extensions are disabled?: Yes

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 11
  • Comments: 15 (3 by maintainers)

Most upvoted comments

I’m running into this same issue on my project with this tsconfig.json:

{
  "compilerOptions": {
    "target": "es5",
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react",
    "lib": ["dom", "dom.iterable", "esnext"],
    "downlevelIteration": true,
    "declaration": true,
    "outDir": "build"
  },
  "include": ["src", "tests"]
}

Commenting out esModuleInterop and allowSyntheticDefaultImports seems to fix it, but then I can’t do things like:

import React, {
  ReactElement,
  useState,
  useEffect,
  useCallback,
  useContext,
} from 'react';

As it expects:

import * as React from 'react';

And here is the output log for it:

[2020-07-28 12:21:42.514] [exthost] [error] [vscode.typescript-language-features] provider FAILED
[2020-07-28 12:21:42.514] [exthost] [error] Error: <semantic> TypeScript Server Error (3.9.7)
Debug Failure. Alias targets of default exports must have a parent
Error: Debug Failure. Alias targets of default exports must have a parent
    at getDefaultExportInfoWorker (/Users/jimmy.multani/projects/rakuten/vertical/gift-cards-web/node_modules/typescript/lib/tsserver.js:130039:80)
    at getDefaultLikeExportInfo (/Users/jimmy.multani/projects/rakuten/vertical/gift-cards-web/node_modules/typescript/lib/tsserver.js:129995:24)
    at /Users/jimmy.multani/projects/rakuten/vertical/gift-cards-web/node_modules/typescript/lib/tsserver.js:129978:35
    at /Users/jimmy.multani/projects/rakuten/vertical/gift-cards-web/node_modules/typescript/lib/tsserver.js:130214:25
    at forEachExternalModule (/Users/jimmy.multani/projects/rakuten/vertical/gift-cards-web/node_modules/typescript/lib/tsserver.js:130239:17)
    at forEachExternalModuleToImportFrom (/Users/jimmy.multani/projects/rakuten/vertical/gift-cards-web/node_modules/typescript/lib/tsserver.js:130211:13)
    at getExportInfos (/Users/jimmy.multani/projects/rakuten/vertical/gift-cards-web/node_modules/typescript/lib/tsserver.js:129976:13)
    at getFixesInfoForNonUMDImport (/Users/jimmy.multani/projects/rakuten/vertical/gift-cards-web/node_modules/typescript/lib/tsserver.js:129961:31)
    at getFixesInfo (/Users/jimmy.multani/projects/rakuten/vertical/gift-cards-web/node_modules/typescript/lib/tsserver.js:129894:50)
    at Object.getCodeActions (/Users/jimmy.multani/projects/rakuten/vertical/gift-cards-web/node_modules/typescript/lib/tsserver.js:129567:28)
    at /Users/jimmy.multani/projects/rakuten/vertical/gift-cards-web/node_modules/typescript/lib/tsserver.js:127394:77
    at Object.flatMap (/Users/jimmy.multani/projects/rakuten/vertical/gift-cards-web/node_modules/typescript/lib/tsserver.js:465:25)
    at Object.getFixes (/Users/jimmy.multani/projects/rakuten/vertical/gift-cards-web/node_modules/typescript/lib/tsserver.js:127394:23)
    at /Users/jimmy.multani/projects/rakuten/vertical/gift-cards-web/node_modules/typescript/lib/tsserver.js:139206:35
    at Object.flatMap (/Users/jimmy.multani/projects/rakuten/vertical/gift-cards-web/node_modules/typescript/lib/tsserver.js:465:25)
    at Proxy.getCodeFixesAtPosition (/Users/jimmy.multani/projects/rakuten/vertical/gift-cards-web/node_modules/typescript/lib/tsserver.js:139204:23)
    at Proxy.<anonymous> (/Users/jimmy.multani/.vscode/extensions/jpoissonnier.vscode-styled-components-0.0.29/node_modules/typescript-template-language-service-decorator/lib/template-language-service-decorator.js:144:20)
    at IOSession.Session.getCodeFixes (/Users/jimmy.multani/projects/rakuten/vertical/gift-cards-web/node_modules/typescript/lib/tsserver.js:149305:64)
    at Session.handlers.ts.createMapFromTemplate._a.<computed> (/Users/jimmy.multani/projects/rakuten/vertical/gift-cards-web/node_modules/typescript/lib/tsserver.js:148042:61)
    at /Users/jimmy.multani/projects/rakuten/vertical/gift-cards-web/node_modules/typescript/lib/tsserver.js:149555:88
    at IOSession.Session.executeWithRequestId (/Users/jimmy.multani/projects/rakuten/vertical/gift-cards-web/node_modules/typescript/lib/tsserver.js:149546:28)
    at IOSession.Session.executeCommand (/Users/jimmy.multani/projects/rakuten/vertical/gift-cards-web/node_modules/typescript/lib/tsserver.js:149555:33)
    at IOSession.Session.onMessage (/Users/jimmy.multani/projects/rakuten/vertical/gift-cards-web/node_modules/typescript/lib/tsserver.js:149579:35)
    at Interface.<anonymous> (/Users/jimmy.multani/projects/rakuten/vertical/gift-cards-web/node_modules/typescript/lib/tsserver.js:150895:27)
    at Interface.emit (events.js:203:13)
    at Interface._onLine (readline.js:316:10)
    at Interface._normalWrite (readline.js:461:12)
    at Socket.ondata (readline.js:172:10)
    at Socket.emit (events.js:203:13)
    at addChunk (_stream_readable.js:295:12)
    at readableAddChunk (_stream_readable.js:276:11)
    at Socket.Readable.push (_stream_readable.js:210:10)
    at Pipe.onStreamRead (internal/stream_base_commons.js:166:17)
	at Function.create (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/typescript-language-features/dist/extension.js:1:55161)
	at h.dispatchResponse (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/typescript-language-features/dist/extension.js:1:227777)
	at h.dispatchMessage (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/typescript-language-features/dist/extension.js:1:226697)
	at /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/typescript-language-features/dist/extension.js:1:226173
	at l.fire (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:45:801)
	at l.onLengthData (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/typescript-language-features/dist/extension.js:1:235493)
	at Socket.<anonymous> (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/typescript-language-features/dist/extension.js:1:235141)
	at Socket.emit (events.js:203:13)
	at addChunk (_stream_readable.js:295:12)
	at readableAddChunk (_stream_readable.js:276:11)
	at Socket.Readable.push (_stream_readable.js:210:10)
	at Pipe.onStreamRead (internal/stream_base_commons.js:166:17)