documentation icon indicating copy to clipboard operation
documentation copied to clipboard

TypeScript imports cannot be resolved

Open kripod opened this issue 6 years ago • 10 comments

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

kripod avatar Jun 18 '19 20:06 kripod

We should probably add ts to requireExtension defaults. https://github.com/documentationjs/documentation/blob/4ea3a95539513029fc1bafddad4e770934b7d019/src/input/dependency.js#L64

Try running with --require-extension=ts?

tmcw avatar Jun 18 '19 20:06 tmcw

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

kripod avatar Jun 18 '19 20:06 kripod

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.

kripod avatar Jun 18 '19 20:06 kripod

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

tmcw avatar Jun 18 '19 21:06 tmcw

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

kripod avatar Jun 18 '19 21:06 kripod

No luck here either. Made a new issue: https://github.com/documentationjs/documentation/issues/1272

trusktr avatar Aug 09 '19 17:08 trusktr

--shallow

cekvenich avatar Aug 20 '19 13:08 cekvenich

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

AndyOGo avatar Nov 22 '20 00:11 AndyOGo

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.

JaccoGoris avatar Jul 29 '21 12:07 JaccoGoris

I've submitted #1484 to fix this.

buschtoens avatar Feb 27 '22 06:02 buschtoens