You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Move to a new file doesn't add extension with "module": "nodeNext" leading to a broken importΒ #50710
This is the behavior in every version I tried, and I reviewed the FAQ for entries about extensions
β― Playground Link
N/A Only applies to multi-file refactoring
π» Code
// Refactor this function to a new filefunctionsomeLibFn(): string{returnsomeOtherFn();}functionsomeOtherFn(): string{return"hello world!";}console.log(someLibFn());
π Actual behavior
The import generated is missing the .js extension.
i.e. This is generated:
import{someLibFn}from"./someLibFn";
Similarly in the other file the reverse import is also missing it's extension:
import{someOtherFn}from"./example";
This broken refactor produces a predictable TS error:
Relative import paths need explicit file extensions in EcmaScript imports when '--moduleResolution' is 'node16' or 'nodenext'. Did you mean './someLibFn.js'?ts(2835)
See also as video:
Screencast.from.11-09-22.00.10.49.webm
π Expected behavior
It should generate with the .js extension as (and ditto for the other file):
import{someLibFn}from"./someLibFn.js";
Notes
This is almost certainly related to #46290 . However this doesn't really have anything to do with the vscode specific option importModuleSpecifierEnding, so I made a separate issue.
tsconfig.json
In case this issue is caused by a combination of settings here is the full tsconfig.json:
changed the title [-]Move to a new file doesn't add extension with "module": "nodeNext" leading to a broken module[/-][+]Move to a new file doesn't add extension with "module": "nodeNext" leading to a broken import[/+]on Sep 10, 2022
Just curious, we have a TypeScript file/code and we want to move it to a new file (JavaScript file? π ) and import that code from the JavaScript file - am I right?
Activity
[-]Move to a new file doesn't add extension with "module": "nodeNext" leading to a broken module[/-][+]Move to a new file doesn't add extension with "module": "nodeNext" leading to a broken import[/+]a-tarasyuk commentedon Sep 13, 2022
Just curious, we have a TypeScript file/code and we want to move it to a new file (JavaScript file? π ) and import that code from the JavaScript file - am I right?
/cc Andrew Branch (@andrewbranch)
andrewbranch commentedon Sep 13, 2022
It looks like both files are TypeScript from the screencast, but I donβt think it really matters.
egasimus commentedon Sep 19, 2022
(fix #50725, #50710) add file extensions in import statements (#51702)