Skip to content

TypeScript imports cannot be resolved #1258

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

Closed
kripod opened this issue Jun 18, 2019 · 10 comments · Fixed by #1484
Closed

TypeScript imports cannot be resolved #1258

kripod opened this issue Jun 18, 2019 · 10 comments · Fixed by #1484

Comments

@kripod
Copy link
Contributor

kripod commented Jun 18, 2019

Input

CLI command

yarn documentation build --document-exported src/index.ts --format md --github

src/index.ts

export { default as useDeviceMotion } from './useDeviceMotion'; // Missing '.ts' extension

src/useDeviceMotion.ts

import { useEffect, useState } from 'react';
import { managedEventListener } from './utils'; // Missing '.ts' extension

export default function useDeviceMotion() {
  const [motion, setMotion] = useState({});
  // ...
  return motion;
}

Output

Error: Cannot find module 'D:\Development\Projects\my-project\src\useDeviceMotion'
Require stack:
- D:\Development\Projects\my-project\node_modules\documentation\src\extractors\exported.js
- D:\Development\Projects\my-project\node_modules\documentation\src\parsers\javascript.js
- D:\Development\Projects\my-project\node_modules\documentation\src\index.js
- D:\Development\Projects\my-project\node_modules\documentation\src\commands\build.js
- D:\Development\Projects\my-project\node_modules\documentation\src\commands\index.js
- D:\Development\Projects\my-project\node_modules\documentation\bin\documentation.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:623:15)
    at Function.resolve (internal/modules/cjs/helpers.js:21:19)
    at getCachedData (D:\Development\Projects\my-project\node_modules\documentation\src\extractors\exported.js:179:20)
    at findExportDeclaration (D:\Development\Projects\my-project\node_modules\documentation\src\extractors\exported.js:207:15)
    at D:\Development\Projects\my-project\node_modules\documentation\src\extractors\exported.js:110:25
    at Array.forEach (<anonymous>)
    at ExportDeclaration (D:\Development\Projects\my-project\node_modules\documentation\src\extractors\exported.js:97:20)
    at NodePath._call (D:\Development\Projects\my-project\node_modules\@babel\traverse\lib\path\context.js:53:20)
    at NodePath.call (D:\Development\Projects\my-project\node_modules\@babel\traverse\lib\path\context.js:40:17)
    at NodePath.visit (D:\Development\Projects\my-project\node_modules\@babel\traverse\lib\path\context.js:88:12)
error Command failed with exit code 1.

Environment

  • What version of documentation.js are you using?: 11.0.1
  • How are you running documentation.js (on the CLI, Node.js API, Grunt, other?): CLI
@tmcw
Copy link
Member

tmcw commented Jun 18, 2019

We should probably add ts to requireExtension defaults.

.concat(['.mjs', '.js', '.json', '.es6', '.jsx']),

Try running with --require-extension=ts?

@kripod
Copy link
Contributor Author

kripod commented Jun 18, 2019

@tmcw Thank you for the quick tip! Unfortunately, it still fails...

@kripod
Copy link
Contributor Author

kripod commented Jun 18, 2019

Actually, yarn documentation build src/*.ts --format md --parse-extension=ts seems to be working, although it's a bit hacky.

The issue seems to be something with --document-exported.

@tmcw
Copy link
Member

tmcw commented Jun 18, 2019

Whoops, try --require-extension=.ts? Forgot that there's a . necessary.

@kripod
Copy link
Contributor Author

kripod commented Jun 18, 2019

@tmcw I already tried that, doesn't seem to work either.

@trusktr
Copy link

trusktr commented Aug 9, 2019

No luck here either. Made a new issue: #1272

@cekvenich
Copy link

--shallow

@AndyOGo
Copy link

AndyOGo commented Nov 22, 2020

--require-extension .ts and --parse-extension ts do not help to import referenced ts files

@JaccoGoris
Copy link

JaccoGoris commented Jul 29, 2021

Hi, is there any new information on this? I am having the same problem, when I add --document-exported it fails on imports without the .ts extension. unfortunately wen I do that, typescript starts complaining (and possible the other devs in my company hehe). So it seems I'm stuck between a rock and a hard place here.

@buschtoens
Copy link
Contributor

I've submitted #1484 to fix this.

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