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

An import path cannot end with a '.ts' extension. #21

Closed
timotius02 opened this issue Apr 5, 2022 · 10 comments
Closed

An import path cannot end with a '.ts' extension. #21

timotius02 opened this issue Apr 5, 2022 · 10 comments
Labels
bug Something isn't working

Comments

@timotius02
Copy link
Contributor

Getting this error in my build when trying out the library. Probably due to the .ts ending in the name of the library.

Currently using the default Typescript environment setup w/ Remix.

@Moebits
Copy link
Owner

Moebits commented Apr 5, 2022

You need to set moduleResolution to node intsconfig.json, otherwise it thinks you are importing a local file named youtube.ts. Having ".ts" extension in module names is allowed and I've never had issues with it.

{
    "compilerOptions": {
      "moduleResolution": "node"
    }
}

@Moebits Moebits added the question Further information is requested label Apr 5, 2022
@timotius02
Copy link
Contributor Author

I already had module resolution to node. This is my exact tsconfig.

{
  "include": ["remix.env.d.ts", "**/*.ts", "**/*.tsx"],
  "compilerOptions": {
    "lib": ["DOM", "DOM.Iterable", "ES2019"],
    "isolatedModules": true,
    "esModuleInterop": true,
    "jsx": "react-jsx",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "target": "ES2019",
    "strict": true,
    "baseUrl": ".",
    "paths": {
      "~/*": ["./app/*"]
    },

    // Remix takes care of building everything in `remix build`.
    "noEmit": true
  }
}

@Moebits
Copy link
Owner

Moebits commented Apr 5, 2022

Then the error is being generated by your linter, not the typescript compiler. You need to find any rules that say "no import with .ts extension" in your linter config and disable it.

@Moebits Moebits added invalid This doesn't seem right and removed question Further information is requested labels Apr 5, 2022
@Moebits Moebits closed this as completed Apr 5, 2022
@timotius02
Copy link
Contributor Author

timotius02 commented Apr 6, 2022

It seem like it is not a linting issue. I've tried ignoring the line and disabling my whole linter but it is still erroring. The only way to get it to not error is to use @ts-ignore but that makes the library lose all of its typings. Update: I'm able to use Moq.ts perfectly fine, but not this library.

@Moebits
Copy link
Owner

Moebits commented Apr 6, 2022

Using @ts-ignore should not make it lose all of its typings. At least, this is not what should happen in Visual Studio Code. It might be different in other IDE's because displaying the typings is an IDE feature. I suspect that the error you're having is also an IDE error if it is not the ts compiler or linter. I would try switching over to VS Code.
Screen Shot 2022-04-06 at 1 52 13 PM

@Moebits Moebits reopened this Apr 6, 2022
@Moebits Moebits added unknown and removed invalid This doesn't seem right labels Apr 6, 2022
@timotius02
Copy link
Contributor Author

I am also already using VS Code, and yes they do disappear.

vscode

@Moebits
Copy link
Owner

Moebits commented Apr 6, 2022

I hate stating the obvious, but you need to reinstall because all your issues sound like you don't have it installed.

npm uninstall youtube.ts
npm install youtube.ts

Also, does this issue occur on a vanilla typescript project (no frameworks like Remix). If it doesn't, you know that it's because of some compiler/linter config set by Remix that you have to change.

@codetheweb
Copy link
Contributor

I'm running into the same issue with a fairly vanilla Typescript config:

{
  "compilerOptions": {
    "lib": ["ES2019", "DOM"],
    "target": "es2018",
    "module": "ES2020",
    "moduleResolution": "node",
    "declaration": true,
    "strict": true,
    "experimentalDecorators": true,
    "esModuleInterop": true,
    "sourceMap": true,
    "resolveJsonModule": true,
    "noEmit": true
  },
  "include": ["src"],
  "exclude": ["node_modules"]
}

yarn tsc:

Error: src/services/third-party.ts(3,21): error TS2691: An import path cannot end with a '.ts' extension. Consider importing 'youtube.js' instead.
Error: src/services/youtube-api.ts(5,58): error TS2691: An import path cannot end with a '.ts' extension. Consider importing 'youtube.js' instead.

@Moebits
Copy link
Owner

Moebits commented Apr 7, 2022

Okay, I renamed the file Youtube.ts to youtube.ts which should fix an issue on case-sensitive file systems, update to v0.2.8.

@Moebits Moebits added bug Something isn't working and removed unknown labels Apr 8, 2022
@Moebits Moebits closed this as completed Apr 8, 2022
@codetheweb
Copy link
Contributor

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants