Skip to content

Might there be an issue if two source files import the same source file via different syntax? #11

@rwv37

Description

@rwv37

I've been using vite-plugin-tsconfig-paths for a while now, and had everything in my project working as I would expect. I then decided to make some changes to the organization of my source directory tree (like, moving the directory src/bar to src/foo/bar). After doing so, I started getting what seemed to me to be a very weird error: My dependency injection container (tsyringe) started complaining that it couldn't resolve my logging singleton. The reason this struck me as "very weird" is that I was informed of this via a log message, and that log message used my logging singleton... which had been resolved by my DI container.

Eventually I noticed that when I changed the source directory organization, my IDE (VSCode) changed some of the import statements like import { bling } from '~/bar/bling' to import { bling } from '~/foo/bar/bling (where I'm using tsc mapping to resolve ~/* to /src/*), but others to relative path stuff like import { bling } from '../../foo/bar/bling'.

In particular, I have a DITokens.ts file wherein the various DI lookup tokens are defined. In the file where tsyringe couldn't resolve my logger, DITokens.ts was imported via one syntax (I forget which, but let's say ~). An error was thrown from there by tsyringe. The error eventually bubbled up to another file, wherein DITokens.ts was imported via the other syntax (say, ../..), which caught the error and logged it.

Successfully.

Via my logger.

Which it had obtained by asking tsyringe to resolve it.

So, I was guessing that maybe after all of the translation from Typescript to JavaScript, the rolling-up, and whatever else, there were now actually two entirely different objects representing what should have been the same DI token. One such token had been registered with the container at startup time, but the container had no idea about the other one.

I then manually changed all of the imports of DITokens.ts to use the ~ syntax. With that one change, everything started working again.

I don't know that vite-plugin-tsconfig-paths is what's causing this, but it seems like the place to start. Is it possible that it's considering the same file, referenced by the two different syntaxes, to be entirely different things?

Thanks in advance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions