-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Resolving .js file extensions to .ts file extensions in imports #2729
Comments
I'm using settings: {
'import/resolver': {
typescript: {
alwaysTryTypes: true,
},
},
}, |
Also make sure to actually install |
Sounds like this is answered. |
@ljharb actually, it only seems to work if |
I tried to follow the instructions and installed the Below is my full config, in case it helps. Any news on the pending draft for extensionAlias? @phryneas // @ts-check
const { defineConfig } = require("eslint-define-config");
module.exports = defineConfig({
extends: [
"prettier",
"turbo",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:import/recommended",
"plugin:import/typescript",
],
parser: "@typescript-eslint/parser",
settings: {
"import/resolver": {
typescript: { alwaysTryTypes: true },
node: true,
},
},
parserOptions: {
project: "./tsconfig.json",
},
rules: {
"@typescript-eslint/no-unused-vars": [
"error",
{ args: "after-used", argsIgnorePattern: "^_", varsIgnorePattern: "^_" },
],
"@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/no-misused-promises": "error",
"@typescript-eslint/consistent-type-imports": "warn",
"@typescript-eslint/consistent-type-definitions": ["warn", "type"],
"@typescript-eslint/no-import-type-side-effects": "warn",
"array-callback-return": "warn",
"unused-imports/no-unused-imports": "warn",
"no-template-curly-in-string": "error",
"turbo/no-undeclared-env-vars": "off",
},
plugins: ["@typescript-eslint", "unused-imports", "import"],
ignorePatterns: ["**/node_modules/**", "**/dist/**", "/*.*"],
}); |
any update here? I'm having issue in a project that uses
|
I don't understand what's the issue with typescript resolver, please provide minimal but runnable online reproduction. I'd like to close this issue here, if you have further question, you should raise issue on TypeScript resolver's side. |
@JounQin I believe that the inability of Seems like there's also a PR open for that here in the |
I love this project. I'm very excited to get it up and running.
The problem I'm running into is that my example.ts file has an import in it like this:
The file that actually points to is "../src/environment-config.ts".
ts-node-esm example.ts
seems to handle the module resolution for me magically; it just works. Additionally, when I build from project with typescript, it also just works because the .ts files get changed to .js, so the ".js" file extension in the import paths points to the right file when I execute the file with Node:node example.js
.It seems ideal to me to keep this configuration. However, I cannot get the eslint-plugin-import to resolve ".js" to ".ts" in my imports. I've spent a few hours on it, looking for resolvers on NPM that might do this and trying to write my own resolver. I didn't find anything on NPM and in writing my own resolver, I realized that module resolution is a bit more complex than I anticipated. I also looked at
eslint-import-resolver-typescript
, but that seems to be created to support .ts file extensions in your imports, which I do not have. I've also tried searching the issues on this repo and was not able to find anything related.I am wondering if there is something simple that I am missing to achieve this. I am not particularly knowledgable about module resolution, or the best way to make all of this work. If possible, any thoughts/help would be greatly appreciated. Thank you very much.
Here is my .eslintrc.cjs:
The text was updated successfully, but these errors were encountered: