Skip to content

Missing ts(2307) on side effect importsΒ #56619

@MaciejZoopit

Description

@MaciejZoopit

πŸ” Search Terms

compiler option to prevent importing non-existent files

βœ… Viability Checklist

⭐ Suggestion

I would like to see an error when importing a module, that doesn't exist

πŸ“ƒ Motivating Example

I have util repo, where I recently added a module called new-module
In other repos I wanted to import it, I did it like that:
import '@company/util/cjs/new-module'

And the problem is that TS doesn't care if this module exists. I get no error even when I do this:
import 'asdasd'

Before I deployed my changes I should have updated util to the newer version with new-module, but I forgot. I wish TS informed me that this module doesn't exist for this version of util and prevented me from building the code.

My suggestion is to add a check to this:
import '@company/util/cjs/new-module'

πŸ’» Use Cases

  1. Validate imports of modules
  2. Modules are not validated
  3. My current workaround is:
import {} from '@company/util/cjs/new-module'
import '@company/util/cjs/new-module'

One line checks if I have the module and the other imports it. Not very neat though

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions