Skip to content

File extension substitution is not working #275

Open
@magnusriga

Description

@magnusriga

Hi,

Thanks for a solid resolver. I am having an issue though, please see below.

According to the ts docs:

For any module specifier that would, according to the moduleResolution algorithm specified, trigger a lookup of a JavaScript file in the runtime or bundler, TypeScript will first try to find a TypeScript implementation file or type declaration file with the same name and analagous file extension.

However, the below file and corresponding package.json (minimal repo here) throws this error:

Unable to resolve path to module '#app/bar'.eslint(import/no-unresolved)

File Excerpts

// foo.tsx
import { Bar } from "#app/bar"; // Resolved by TS, but lacking Intellisense (ctrl+space suggestions). ESLint import/no-unresolved rule also throws an error.
import { Baz } from "my-app/baz"; // Resolved by TS, but lacking Intellisense (ctrl+space suggestions). ESLint import/no-unresolved rule also throws an error.
import { Qux } from "./qux"; // Resolved by TS. Also works with Intellisense (ctrl+space suggestions), and eslint import/no-unresolved rule.

export const Foo = () => {
  return (
    <>
      <Bar bar="bar" />
      <Baz baz="baz" />
      <Qux qux="qux" />
    </>
  );
};
// bar.tsx
export const Bar = ({bar}: {bar: string}) => {
  return <div>{bar}</div>
}
// package.json
{
...
 "name": "my-app",
  "imports": {
    "#app/*": "./src/app/*.js"
  },
  "exports": {
    "./*": "./src/app/*.js"
  },
...

I am using "typescript": "5.5.0-dev.20240314". Typescript finds the file, so it is only the import resolver that cannot find it.

The error disappears if we change .js to .tsx in package.json, however that is not recommended practice. The TypeScript docs are very clear on the point that the package config should point to the output JS file(s), not the input TS files. Otherwise, the app might not work runtime, when consumed.

Any idea what is going on?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions