The file the import or import-like reference is contained within
The module reference string
The compiler options for the program that owns the file. If the file belongs to a referenced project, the compiler options should be the options of the referenced project, not the referencing project.
The final resolution mode of the import
Use
program.getModeForUsageLocation, which retrieves the correctcompilerOptions, instead of this function whenever possible. Calculates the final resolution mode for a given module reference node. This function only returns a result when module resolution settings allow differing resolution between ESM imports and CJS requires, or when a mode is explicitly provided via import attributes, which cause animportorrequirecondition to be used during resolution regardless of module resolution settings. In absence of overriding attributes, and in modes that support differing resolution, the result indicates the syntax the usage would emit to JavaScript. Some examples: