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

Unable to execute "move to new file" on constant referencing nextjs type #60912

Open
dnjstrom opened this issue Jan 4, 2025 · 0 comments
Open
Labels
Bug A bug in TypeScript Help Wanted You can do this
Milestone

Comments

@dnjstrom
Copy link

dnjstrom commented Jan 4, 2025

πŸ”Ž Search Terms

"move to new file", "addImportFromExportedSymbol", "Debug Failure"

πŸ•— Version & Regression Information

  • This changed between versions 5.4 and 5.5 and is present on the current nightly 5.8.0-dev.20250104

⏯ Playground Link

Minimal reproduction with instructions: https://github.com/dnjstrom/move-to-new-file-next-repro

πŸ’» Code

import type { Metadata } from "next";

const metadata: Metadata = {};

export default metadata;

πŸ™ Actual behavior

Trying to execute the "Move to a new file" refactoring on the const metadata: Metadata = {}; line does nothing and an error is logged by the tsserver.

Err 5265  [22:21:07.805] Exception on executing command {
  "seq": 1007,
  "type": "request",
  "command": "getEditsForRefactor",
  "arguments": {
    "file": "/Users/daniel/Code/move-to-new-file-repro/src/next.ts",
    "startLine": 3,
    "startOffset": 1,
    "endLine": 3,
    "endOffset": 31,
    "refactor": "Move to a new file",
    "action": "Move to a new file",
    "startPosition": 39,
    "endPosition": 69
  }
}:

    Debug Failure.

    Error: Debug Failure.
        at Object.addImportFromExportedSymbol (/Users/daniel/Code/move-to-new-file-repro/node_modules/typescript/lib/typescript.js:154243:32)
        at /Users/daniel/Code/move-to-new-file-repro/node_modules/typescript/lib/typescript.js:144288:19
        at Map.forEach (<anonymous>)
        at addTargetFileImports (/Users/daniel/Code/move-to-new-file-repro/node_modules/typescript/lib/typescript.js:144282:17)
        at getNewStatementsAndRemoveFromOldFile (/Users/daniel/Code/move-to-new-file-repro/node_modules/typescript/lib/typescript.js:143512:3)
        at doChange4 (/Users/daniel/Code/move-to-new-file-repro/node_modules/typescript/lib/typescript.js:144488:3)
        at /Users/daniel/Code/move-to-new-file-repro/node_modules/typescript/lib/typescript.js:144477:77
        at _ChangeTracker.with (/Users/daniel/Code/move-to-new-file-repro/node_modules/typescript/lib/typescript.js:174306:5)
        at Object.getRefactorEditsToMoveToNewFile [as getEditsForAction] (/Users/daniel/Code/move-to-new-file-repro/node_modules/typescript/lib/typescript.js:144477:60)
        at Object.getEditsForRefactor (/Users/daniel/Code/move-to-new-file-repro/node_modules/typescript/lib/typescript.js:142603:31)
        at Object.getEditsForRefactor2 [as getEditsForRefactor] (/Users/daniel/Code/move-to-new-file-repro/node_modules/typescript/lib/typescript.js:149939:32)
        at proxy.<computed> [as getEditsForRefactor] (/Users/daniel/.vscode/extensions/mxsdev.typescript-explorer-0.4.2/node_modules/@ts-type-explorer/typescript-plugin/dist/index.js:15:15)
        at IpcIOSession.getEditsForRefactor (/Users/daniel/Code/move-to-new-file-repro/node_modules/typescript/lib/typescript.js:191087:49)
        at getEditsForRefactor (/Users/daniel/Code/move-to-new-file-repro/node_modules/typescript/lib/typescript.js:189305:43)
        at /Users/daniel/Code/move-to-new-file-repro/node_modules/typescript/lib/typescript.js:191491:69
        at IpcIOSession.executeWithRequestId (/Users/daniel/Code/move-to-new-file-repro/node_modules/typescript/lib/typescript.js:191483:14)
        at IpcIOSession.executeCommand (/Users/daniel/Code/move-to-new-file-repro/node_modules/typescript/lib/typescript.js:191491:29)
        at IpcIOSession.onMessage (/Users/daniel/Code/move-to-new-file-repro/node_modules/typescript/lib/typescript.js:191533:51)
        at process.<anonymous> (/Users/daniel/Code/move-to-new-file-repro/node_modules/typescript/lib/tsserver.js:523:14)
        at process.emit (node:events:518:28)
        at emit (node:internal/child_process:950:14)
        at process.processTicksAndRejections (node:internal/process/task_queues:83:21)

File text of /Users/daniel/Code/move-to-new-file-repro/src/next.ts:
    import type { Metadata } from "next";

    const metadata: Metadata = {};

    export default metadata;

πŸ™‚ Expected behavior

The metadata constant should be moved to a separate file

Additional information about the issue

This appears to be to some degree a specific interaction with the next module, as doing the same thing with a type from react works well. Downgrading to typescript 5.4 also works.

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Help Wanted You can do this labels Jan 6, 2025
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

2 participants