Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeDoc complains "Cannot find module"

I have a Typsecript based react app. It works fine but I want to add TypeDoc (think JSDoc for Typescript) to the mix. After installing it I run this from the command line (only processing a single file as I test this):

typedoc --module commonjs --jsx react --out ../docs/ ./src/components/404/404.tsx

and I get an error:

Error: /path/to/project/src/components/404/404.tsx(0)
 Cannot find module 'react'.

React is, in fact, installed. I have tried running TypeDoc installed globally and locally and it makes no difference (thought maybe the global install was unable to find the correct node_modules). The app compiles from Typescript and runs fine... no complaints about missing modules or type defs... just won't work via TypeDoc.

Any suggestions? It seems that in order to generate documentation in a Typescript based React project, TypeDoc is the only game in town so I'm a bit stuck.

like image 921
rg88 Avatar asked Mar 21 '16 19:03

rg88


People also ask

How to solve the “cannot find module or its corresponding type declarations” error?

The "Cannot find module or its corresponding type declarations" error occurs when TypeScript cannot locate a third-party or local module in our project. To solve the error, make sure to install the module and try setting moduleResolution to node in your tsconfig.json file. If the module is a third-party module, make sure you have it installed.

Why does the “cannot find module” error happen when loading fonts?

# Why Does the "Cannot find module" Error Happen When Loading Fonts? It happens because of module resolution. You need to declare the font file formats as modules so that TypeScript can understand and parse them correctly. TypeScript relies on definition files (*.d.ts) to figure out what an import refers to.

Why does typescript say cannot find module when importing fonts?

It happens because of module resolution. You need to declare the font file formats as modules so that TypeScript can understand and parse them correctly. TypeScript relies on definition files ( *.d.ts) to figure out what an import refers to. When that information is missing, you get the "Cannot find module" error.

What to do if a module is not working?

If the module is a third-party module, make sure you have it installed. Make sure to replace module-name with the name of the module in your error message. If it is a third-party module you're having problems with, try removing your node-modules and package-lock.json files, re-run npm install and reload your IDE.


1 Answers

Probably it helps you:

'node ./node_modules/typedoc/bin/typedoc ' +
(path || './src/scripts/') +
'--exclude node_modules ' +
'--ignoreCompilerErrors ' +
'--experimentalDecorators ' +
'--target ES6 ' +
'--jsx react'

And I noticed some error in package.json with default theme:

-- "typedoc-default-themes": "0.4.0",

++ "typedoc-default-themes": "0.3.4",

like image 200
Alerkesi Avatar answered Nov 03 '22 22:11

Alerkesi