-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
refactor: New file generates import from wrong module specifier #58897
Comments
I'm having this problem in a Next.js project as well, is it specific to Next? |
Seems like the culprit is something in Example (Works in v5.4.5 but not v5.5.2)Running // apps/web/components/SomeOtherComponent.tsx
import { Button } from "@repo/ui";
export function SomeComponent() {
return (
<div>
Some Component
<Button>Click Me</Button>
</div>
);
}
export function SomeOtherComponent() {
return (
<div>
<SomeComponent />
<div>Some other component</div>
<CheckList value={[]} options={[]} />
</div>
);
}
|
No - It's caused by the typescript version you're using as commented by @nolanleung ealier In your terminal:
And try the command, you'll see that it works ✅ |
this fixed my issue. for anyone else
i was getting this error when attempting to autoimport certain things. TS server logs showed this Info 908 [17:52:51.447] response: but it wouldn't actually add any text to my file, even though it showed the correct autoimport in the list. which means the error was not from TS server? But instead from vscode? Just posting this incase it helps anyone |
Also really annoying that the Move to file and Move to new file has been swapped. I've been using Move to new file for years in the first position, why swap it? |
This really screwed up my flow for about to days, downgrading helped. see #58897 (comment) |
This worked for me! Typescript version 5.4.5 |
It works for me. If someone just faced with this problem - use this workaround |
Does not work for me unfortunately.
output error when moving a Type declaration to a type.ts file.
|
@sidouglas i guess in your case |
The workaround unfortunately doesn't work as smoothly if you don't have a node_modules in the current workspace root, i.e., if you have a monorepo with another sub folder. I also tried the nightly version (via extension typescript nightly) 5.7 and it's broken too. If I do move to file I at the very minimum least see an error. But trying to move to a new file anything bigger than a constant number fails. |
This was also happening to me due to the default VSCode version of TS, even though I was working without typescript on a js file. Doing the steps above and then changing the tsdk version fixed it for me |
Minimal repro: /// <reference path='fourslash.ts' />
// @Filename: /node_modules/zod/types.d.ts
//// declare const objectType: () => {};
////
//// export { objectType as object };
// @Filename: /node_modules/zod/external.d.ts
//// export * from "./types";
// @Filename: /node_modules/zod/index.d.ts
//// import * as z from "./external";
//// export * from "./external";
//// export { z };
//// export default z;
// @Filename: /test.ts
//// import { z } from "zod";
////
//// [|const createIssueSchema = z.object();|]
verify.moveToNewFile({
newFileContents: {
"/test.ts":
`
`,
"/createIssueSchema.ts":
`import { z } from "zod";
const createIssueSchema = z.object();
`,
},
});
|
For those like me that don't understand why they don't have the entry showing up in their command palette, your focused tab has to be a .ts(x) file. |
This is another problem, I use "restart ts server" a lot, since problems with ts server can not auto recover, I have to manual restart. |
@magicdawn since your crash still happens on 5.7, will you open a new issue with your repro? The case originally reported in this thread should no longer crash in 5.7, and I'd need to investigate your case separately |
Does this issue occur when all extensions are disabled?: Yes
Version: 1.90.0 (user setup)
Commit: 89de5a8d4d6205e5b11647eb6a74844ca23d2573
Date: 2024-06-04T19:33:54.889Z
Electron: 29.4.0
ElectronBuildId: 9593362
Chromium: 122.0.6261.156
Node.js: 20.9.0
V8: 12.2.281.27-electron.0
OS: Windows_NT x64 10.0.22631
Steps to Reproduce:
Try refactoring createIssueSchema variable to a new file
2024-06-12 09:20:14.898 [error] <semantic> TypeScript Server Error (5.5.0-dev.20240505) Debug Failure. Error: Debug Failure. at Object.addImportFromExportedSymbol (c:\Users\ASUS\.vscode\extensions\ms-vscode.vscode-typescript-next-5.5.20240505\node_modules\typescript\lib\typescript.js:154711:32) at c:\Users\ASUS\.vscode\extensions\ms-vscode.vscode-typescript-next-5.5.20240505\node_modules\typescript\lib\typescript.js:144661:19 at Map.forEach (<anonymous>) at addTargetFileImports (c:\Users\ASUS\.vscode\extensions\ms-vscode.vscode-typescript-next-5.5.20240505\node_modules\typescript\lib\typescript.js:144655:17) at getNewStatementsAndRemoveFromOldFile (c:\Users\ASUS\.vscode\extensions\ms-vscode.vscode-typescript-next-5.5.20240505\node_modules\typescript\lib\typescript.js:143871:3) at doChange4 (c:\Users\ASUS\.vscode\extensions\ms-vscode.vscode-typescript-next-5.5.20240505\node_modules\typescript\lib\typescript.js:144853:3) at c:\Users\ASUS\.vscode\extensions\ms-vscode.vscode-typescript-next-5.5.20240505\node_modules\typescript\lib\typescript.js:144842:77 at _ChangeTracker.with (c:\Users\ASUS\.vscode\extensions\ms-vscode.vscode-typescript-next-5.5.20240505\node_modules\typescript\lib\typescript.js:174963:5) at Object.getRefactorEditsToMoveToNewFile [as getEditsForAction] (c:\Users\ASUS\.vscode\extensions\ms-vscode.vscode-typescript-next-5.5.20240505\node_modules\typescript\lib\typescript.js:144842:60) at Object.getEditsForRefactor (c:\Users\ASUS\.vscode\extensions\ms-vscode.vscode-typescript-next-5.5.20240505\node_modules\typescript\lib\typescript.js:142944:31) at Object.getEditsForRefactor2 [as getEditsForRefactor] (c:\Users\ASUS\.vscode\extensions\ms-vscode.vscode-typescript-next-5.5.20240505\node_modules\typescript\lib\typescript.js:150350:32) at IpcIOSession.getEditsForRefactor (c:\Users\ASUS\.vscode\extensions\ms-vscode.vscode-typescript-next-5.5.20240505\node_modules\typescript\lib\typescript.js:191692:49) at getEditsForRefactor (c:\Users\ASUS\.vscode\extensions\ms-vscode.vscode-typescript-next-5.5.20240505\node_modules\typescript\lib\typescript.js:189914:43) at c:\Users\ASUS\.vscode\extensions\ms-vscode.vscode-typescript-next-5.5.20240505\node_modules\typescript\lib\typescript.js:192078:69 at IpcIOSession.executeWithRequestId (c:\Users\ASUS\.vscode\extensions\ms-vscode.vscode-typescript-next-5.5.20240505\node_modules\typescript\lib\typescript.js:192070:14) at IpcIOSession.executeCommand (c:\Users\ASUS\.vscode\extensions\ms-vscode.vscode-typescript-next-5.5.20240505\node_modules\typescript\lib\typescript.js:192078:29) at IpcIOSession.onMessage (c:\Users\ASUS\.vscode\extensions\ms-vscode.vscode-typescript-next-5.5.20240505\node_modules\typescript\lib\typescript.js:192120:51) at process.<anonymous> (c:\Users\ASUS\.vscode\extensions\ms-vscode.vscode-typescript-next-5.5.20240505\node_modules\typescript\lib\tsserver.js:528:14) at process.emit (node:events:514:28) at emit (node:internal/child_process:951:14) at process.processTicksAndRejections (node:internal/process/task_queues:83:21): Error: <semantic> TypeScript Server Error (5.5.0-dev.20240505) Debug Failure. Error: Debug Failure. at Object.addImportFromExportedSymbol (c:\Users\ASUS\.vscode\extensions\ms-vscode.vscode-typescript-next-5.5.20240505\node_modules\typescript\lib\typescript.js:154711:32) at c:\Users\ASUS\.vscode\extensions\ms-vscode.vscode-typescript-next-5.5.20240505\node_modules\typescript\lib\typescript.js:144661:19 at Map.forEach (<anonymous>) at addTargetFileImports (c:\Users\ASUS\.vscode\extensions\ms-vscode.vscode-typescript-next-5.5.20240505\node_modules\typescript\lib\typescript.js:144655:17) at getNewStatementsAndRemoveFromOldFile (c:\Users\ASUS\.vscode\extensions\ms-vscode.vscode-typescript-next-5.5.20240505\node_modules\typescript\lib\typescript.js:143871:3) at doChange4 (c:\Users\ASUS\.vscode\extensions\ms-vscode.vscode-typescript-next-5.5.20240505\node_modules\typescript\lib\typescript.js:144853:3) at c:\Users\ASUS\.vscode\extensions\ms-vscode.vscode-typescript-next-5.5.20240505\node_modules\typescript\lib\typescript.js:144842:77 at _ChangeTracker.with (c:\Users\ASUS\.vscode\extensions\ms-vscode.vscode-typescript-next-5.5.20240505\node_modules\typescript\lib\typescript.js:174963:5) at Object.getRefactorEditsToMoveToNewFile [as getEditsForAction] (c:\Users\ASUS\.vscode\extensions\ms-vscode.vscode-typescript-next-5.5.20240505\node_modules\typescript\lib\typescript.js:144842:60) at Object.getEditsForRefactor (c:\Users\ASUS\.vscode\extensions\ms-vscode.vscode-typescript-next-5.5.20240505\node_modules\typescript\lib\typescript.js:142944:31) at Object.getEditsForRefactor2 [as getEditsForRefactor] (c:\Users\ASUS\.vscode\extensions\ms-vscode.vscode-typescript-next-5.5.20240505\node_modules\typescript\lib\typescript.js:150350:32) at IpcIOSession.getEditsForRefactor (c:\Users\ASUS\.vscode\extensions\ms-vscode.vscode-typescript-next-5.5.20240505\node_modules\typescript\lib\typescript.js:191692:49) at getEditsForRefactor (c:\Users\ASUS\.vscode\extensions\ms-vscode.vscode-typescript-next-5.5.20240505\node_modules\typescript\lib\typescript.js:189914:43) at c:\Users\ASUS\.vscode\extensions\ms-vscode.vscode-typescript-next-5.5.20240505\node_modules\typescript\lib\typescript.js:192078:69 at IpcIOSession.executeWithRequestId (c:\Users\ASUS\.vscode\extensions\ms-vscode.vscode-typescript-next-5.5.20240505\node_modules\typescript\lib\typescript.js:192070:14) at IpcIOSession.executeCommand (c:\Users\ASUS\.vscode\extensions\ms-vscode.vscode-typescript-next-5.5.20240505\node_modules\typescript\lib\typescript.js:192078:29) at IpcIOSession.onMessage (c:\Users\ASUS\.vscode\extensions\ms-vscode.vscode-typescript-next-5.5.20240505\node_modules\typescript\lib\typescript.js:192120:51) at process.<anonymous> (c:\Users\ASUS\.vscode\extensions\ms-vscode.vscode-typescript-next-5.5.20240505\node_modules\typescript\lib\tsserver.js:528:14) at process.emit (node:events:514:28) at emit (node:internal/child_process:951:14) at process.processTicksAndRejections (node:internal/process/task_queues:83:21) at n.create (c:\Users\ASUS\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\typescript-language-features\dist\extension.js:1:473136) at v.dispatchResponse (c:\Users\ASUS\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\typescript-language-features\dist\extension.js:1:467106) at v.dispatchMessage (c:\Users\ASUS\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\typescript-language-features\dist\extension.js:1:465950) at ChildProcess.<anonymous> (c:\Users\ASUS\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\typescript-language-features\dist\extension.js:1:465443) at ChildProcess.emit (node:events:514:28) at emit (node:internal/child_process:951:14) at process.processTicksAndRejections (node:internal/process/task_queues:83:21)
tsc version : 5.4.5
The text was updated successfully, but these errors were encountered: