Skip to content

Autocomplete crashes when importing from node_modules #31465

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
MadaraUchiha opened this issue May 19, 2019 · 8 comments
Closed

Autocomplete crashes when importing from node_modules #31465

MadaraUchiha opened this issue May 19, 2019 · 8 comments
Assignees
Labels
Bug A bug in TypeScript Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output

Comments

@MadaraUchiha
Copy link

MadaraUchiha commented May 19, 2019

TypeScript Version: 3.5-rc (but existed for as long as 3.0 at least)

Search Terms:
TypeScript autocomplete crashes import, Debug Failure. at Object.assertDefined getDefaultExportInfoWorker

Code
Irrelevant

Expected behavior:

Actual behavior:

TypeScript server emits an error whenever I try to import. This happens project-wide and when I open a new project under the same directory (i.e. same node_modules), autocomplete works as long as there are no imports at all in this new subproject. Any import to any package from node_modules seems to trigger it (i.e. import React from 'react';) but not imports to relative files in the project, (i.e. import { foo } from './bar';).

This is the stacktrace I get:

[2019-05-19 11:18:39.852] [exthost] [error] Error: TypeScript Server Error (3.5.0-rc)
Debug Failure.
Error: Debug Failure.
    at Object.assertDefined (tsserver.js:1558:24)
    at getDefaultExportInfoWorker (tsserver.js:115338:80)
    at getDefaultLikeExportInfo (tsserver.js:115319:24)
    at tsserver.js:115302:35
    at tsserver.js:115446:21
    at forEachExternalModule (tsserver.js:115459:21)
    at forEachExternalModuleToImportFrom (tsserver.js:115444:13)
    at getExportInfos (tsserver.js:115300:13)
    at getFixesInfoForNonUMDImport (tsserver.js:115286:57)
    at getFixesInfo (tsserver.js:115227:50)
    at Object.getCodeActions (tsserver.js:114989:28)
    at tsserver.js:112637:121
    at Object.flatMap (tsserver.js:573:25)
    at Object.getFixes (tsserver.js:112637:23)
    at tsserver.js:122213:35
    at Object.flatMap (tsserver.js:573:25)
    at Object.getCodeFixesAtPosition (tsserver.js:122211:23)
    at IOSession.Session.getCodeFixes (tsserver.js:131258:64)
    at Session.handlers.ts.createMapFromTemplate._a.(anonymous function) (tsserver.js:130008:61)
    at tsserver.js:131452:88
    at IOSession.Session.executeWithRequestId (tsserver.js:131443:28)
    at IOSession.Session.executeCommand (tsserver.js:131452:33)
    at IOSession.Session.onMessage (tsserver.js:131474:35)
    at Interface.<anonymous> (tsserver.js:132765:27)
    at Interface.emit (events.js:182:13)
    at Interface._onLine (readline.js:290:10)
    at Interface._normalWrite (readline.js:433:12)
    at Socket.ondata (readline.js:149:10)
    at Socket.emit (events.js:182:13)
    at addChunk (_stream_readable.js:279:12)
    at readableAddChunk (_stream_readable.js:264:11)
    at Socket.Readable.push (_stream_readable.js:219:10)
    at Pipe.onread (net.js:636:20)
	at Function.create (/usr/share/code/resources/app/extensions/typescript-language-features/dist/extension.js:1:176329)
	at v.dispatchResponse (/usr/share/code/resources/app/extensions/typescript-language-features/dist/extension.js:1:181697)
	at v.dispatchMessage (/usr/share/code/resources/app/extensions/typescript-language-features/dist/extension.js:1:180449)
	at constructor._reader.onData.e (/usr/share/code/resources/app/extensions/typescript-language-features/dist/extension.js:1:179805)
	at u.fire (/usr/share/code/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:47:720)
	at t.Reader.onLengthData (/usr/share/code/resources/app/extensions/typescript-language-features/dist/extension.js:1:185678)
	at Socket.t.Reader.constructor.e.on.e (/usr/share/code/resources/app/extensions/typescript-language-features/dist/extension.js:1:185326)
	at Socket.emit (events.js:182:13)
	at addChunk (_stream_readable.js:279:12)
	at readableAddChunk (_stream_readable.js:264:11)
	at Socket.Readable.push (_stream_readable.js:219:10)
	at Pipe.onread (net.js:636:20)

Related Issues:
This appears to be a repeating thing: #27857 #27878 #28149

@k-eb
Copy link

k-eb commented May 22, 2019

I have started to see this issue too last week. I am using VSCode 1.34.0 on Windows 10 and the TypeScript version is 3.4.5.

And for me it also does not work if the type to auto-import is in the same project.

@RyanCavanaugh RyanCavanaugh added this to the TypeScript 3.6.0 milestone Jun 12, 2019
@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output labels Jun 12, 2019
@orta
Copy link
Contributor

orta commented Oct 17, 2019

Hi folks, I'd love to dig into this but this issue could really do with some kind of reproduction case - it looks likely related to a specific node module but without an idea of which. it's really just guess work based on the stack trace which hasn't been enough to re-create it locally..

@johanbaath
Copy link

@orta I still have this issue. I tried to create a project which would reproduce the error but so far I've failed. The message with latest VSCode and TypeScript 3.6.3 is:

[2019-10-18 10:28:24.894] [exthost] [error] [vscode.typescript-language-features] provider FAILED
[2019-10-18 10:28:24.894] [exthost] [error] Error: <semantic> TypeScript Server Error (3.6.3)
Debug Failure.
Error: Debug Failure.
    at Object.assertDefined (tsserver.js:2101:24)
    at getDefaultExportInfoWorker (tsserver.js:118907:80)
    at getDefaultLikeExportInfo (tsserver.js:118867:24)
    at tsserver.js:118661:35
    at forEachExternalModule (tsserver.js:119036:21)
    at getAllReExportingModules (tsserver.js:118656:13)
    at Object.getImportCompletionAction (tsserver.js:118642:31)
    at getCompletionEntryCodeActionsAndSourceDisplay (tsserver.js:102585:33)
    at Object.getCompletionEntryDetails (tsserver.js:102549:30)
    at Proxy.getCompletionEntryDetails (tsserver.js:125564:35)
    at tsserver.js:134771:57
    at Object.mapDefined (tsserver.js:680:30)
    at IOSession.Session.getCompletionEntryDetails (tsserver.js:134769:33)
    at Session.handlers.ts.createMapFromTemplate._a.(anonymous function) (tsserver.js:133732:61)
    at tsserver.js:135256:88
    at IOSession.Session.executeWithRequestId (tsserver.js:135247:28)
    at IOSession.Session.executeCommand (tsserver.js:135256:33)
    at IOSession.Session.onMessage (tsserver.js:135279:35)
    at Interface.<anonymous> (tsserver.js:136594:27)
    at Interface.emit (events.js:182:13)
    at Interface._onLine (readline.js:290:10)
    at Interface._normalWrite (readline.js:433:12)
    at Socket.ondata (readline.js:149:10)
    at Socket.emit (events.js:182:13)
    at addChunk (_stream_readable.js:283:12)
    at readableAddChunk (_stream_readable.js:264:11)
    at Socket.Readable.push (_stream_readable.js:219:10)
    at Pipe.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
	at Function.create (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/typescript-language-features/dist/extension.js:53:63415)
	at h.dispatchResponse (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/typescript-language-features/dist/extension.js:53:56570)
	at h.dispatchMessage (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/typescript-language-features/dist/extension.js:53:55468)
	at _reader.onData.e (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/typescript-language-features/dist/extension.js:53:54944)
	at l.fire (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:50:519)
	at t.Reader.onLengthData (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/typescript-language-features/dist/extension.js:53:61635)
	at Socket.e.on.e (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/typescript-language-features/dist/extension.js:53:61283)
	at Socket.emit (events.js:182:13)
	at Socket.EventEmitter.emit (domain.js:442:20)
	at addChunk (_stream_readable.js:283:12)
	at readableAddChunk (_stream_readable.js:264:11)
	at Socket.Readable.push (_stream_readable.js:219:10)
	at Pipe.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)

I tried creating a new project with the exact same dependencies, but it does not produce the same error. I have done a clean install of VSCode, wiped the project from disk and cloned it again, still the same error :(.

Is there some way I can get more detailed information on what file it reads when it crashes?

@orta
Copy link
Contributor

orta commented Oct 18, 2019

I tried creating a new project with the exact same dependencies, but it does not produce the same error. I have done a clean install of VSCode, wiped the project from disk and cloned it again, still the same error :(.

Ouch, that's tough.

For debugging further, I just wrote a doc on how to get the TSServer logs which could hopefully be more useful in trying to understand it from your side.

@willgittoes
Copy link

I was having this issue recently (same stack trace and symptoms as OP), and was trying to redact enough stuff from our codebase that I could make a shareable repro when I found something that fixed the issue for me. There was a case where I was re-exporting a default from a package that didn't have a default. Removing that fixed all my auto-import issues. I actually still see stack traces in the exthost log, but import suggestions and auto-import have resumed working for me.

eg.

A simple module with no default export.
/src/testutils/testutils.tsx:

import { ReactTestInstance, act } from 'react-test-renderer'
import { wait } from '@apollo/react-testing'

// `await waitForApollo()` will wait until mocks are returned from Apollo's MockedProvider.
export const waitForApollo = async () => {
  await act(async () => {
    await wait(0)
  })
}

Because I don't want to import 'test/test' but just import 'test', I have an index.tsx
/src/testutils/index.tsx

export * from './testutils'
export { default } from './testutils' // REMOVE THIS LINE, EVERYTHING WORKS

@orta
Copy link
Contributor

orta commented Mar 26, 2020

Thanks for the repro @willgittoes - I've been able to confirm that this was definitely the issue and that it's fixed on master

My repro repo is https://github.com/orta/31465 - and if you use TS 3.5 and go to file.ts and auto-import waitForApollo then it will crash, if you do it on master - it won't

On top of that we now give errors for the export { default } from './testutils' which I think is likely where the fix came from 👍

@orta orta closed this as completed Mar 26, 2020
@orta
Copy link
Contributor

orta commented Mar 27, 2020

Interesting, so running that on previous versions of typescript you could write:

export * from './testutils'
export { default } from './testutils'

When it wasn't possible, but you can't at all now

@orta orta reopened this Mar 27, 2020
@orta
Copy link
Contributor

orta commented Apr 3, 2020

This was re-opened by accident

@orta orta closed this as completed Apr 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output
Projects
None yet
Development

No branches or pull requests

7 participants