Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import/extensions - Missing file extension "ts" #647

Closed
sekhavati opened this issue Jan 12, 2022 · 3 comments
Closed

import/extensions - Missing file extension "ts" #647

sekhavati opened this issue Jan 12, 2022 · 3 comments

Comments

@sekhavati
Copy link

I'm attempting an upgrade of XO from version 0.43 -> 0.47 and a particular lint rule is erroring wherever local code files are imported:

import { FOO } from "./constants";
   => Missing file extension "ts" for "./constants"    import/extensions

import { logger } from "./logger";
   => Missing file extension "ts" for "./logger"       import/extensions

etc...

Adding a .ts file extension to the import path causes a TypeScript (v4.5.4) compile error:

TS2691: An import path cannot end with a '.ts' extension. Consider importing './logger' instead.

Is there something obvious I'm missing or should this work out of the box with XO?

For context in case it matters, this is a monorepo where every package has a tsconfig.json that extends the root level one, eg:

./repo
├── packages
│   ├── foo
│   │   └── tsconfig.json

|   ├── bar
│   │   └── tsconfig.json
├── tsconfig.json

Root level tsconfig.json:

{
  "extends": "@tsconfig/node14/tsconfig.json",
  "compilerOptions": {
    "resolveJsonModule": true
  },
  "exclude": [
    "node_modules",
    "**/node_modules",
    "**/infra",
    "**/*.spec.ts",
    "**/*.test.ts",
    "**/jest.config.ts",
    "**/__mocks__"
  ]
}

Package level tsconfig.json:

{
  "extends": "../../tsconfig.json",
  "compilerOptions": {
    "outDir": "./build",
  }
}
@sindresorhus
Copy link
Member

TS2691: An import path cannot end with a '.ts' extension. Consider importing './logger' instead.

It's the TS error that is incorrect. It should say that you have to add a .js extension.

@sindresorhus
Copy link
Member

You also have to ensure your project is native ESM. Make sure you read the release notes for all the XO versions you skipped.

https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c

@andersk
Copy link
Contributor

andersk commented Mar 9, 2022

For those using eslint-import-resolver-typescript, there’s an open issue for this problem:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants