typedoc icon indicating copy to clipboard operation
typedoc copied to clipboard

Not able to exclude node_modules folder

Open Migronon opened this issue 10 years ago • 9 comments

I run the following command on an Angular2 project:

typedoc --experimentalDecorators --target 'es5' --module 'commonjs' --externalPattern node_modules --excludeExternals --ignoreCompilerErrors --out docs/ web/

I am apparently not able to properly exclude the node_modules folder from the documentation. Whatever I do, the node_modules packages get documented. This is the folder structure /web _ _/app _ _/assets _ _/e2e _ _/node_modules _ _/typings

I tried using exclude and externalPattern + excludeExternals. I tried many combinations of patterns, but apparently I am doing it wrong. I tried values like this: node_modules /node_modules/ node_modules/** node_modules/*/.ts etc.

I would be very grateful if someone pointed out my mistake and made a couple of examples how the patterns should be defined?

Migronon avatar Oct 28 '16 14:10 Migronon

I used "externalPattern": "**/node_modules/**", or "exclude": "**/node_modules/**" in my typedoc.json (I can't remember which)

jtc10005 avatar Nov 15 '16 18:11 jtc10005

I succeeded with this command. typedoc --excludeExternals --externalPattern "**/node_modules/**" --ignoreCompilerErrors --name "$PROJ_NAME" --mode "file" --out "../document/typedoc/" "$SRC_DIR"

but, printed many error logs.

derushio avatar Oct 28 '17 10:10 derushio

I left the ignoreCompilerErrors off on mine and didn't have any error logs.

The problem I'm trying to solve is having links/references put into the docs that are to my local project's node_modules directory when I generate the documentation. There doesn't seem to be a way to stop that behavior.

Edit: What I ended up doing was adding a "docs:sanitize" to my package.json:

    "docs": "npm run docs:clean && npm run docs:generate && npm run docs:sanitize",
    "docs:clean": "rimraf docs",
    "docs:generate": "typedoc --options typedoc.json --out docs src/lib",
    "docs:sanitize": "sed -i 's|'$PWD'||g' $(find docs -type f)"

btgoodwin avatar Nov 02 '17 13:11 btgoodwin

i can't exclude too

  "scripts": {
    "doc": "typedoc --theme markdown --out ./docs --ignoreCompilerErrors --exclude **/{node_modules,test,doc}/**/* .",
    "doc2": "typedoc --theme markdown --externalPattern \"**/(node_modules|test|doc)/**\" --out ./docs --ignoreCompilerErrors --exclude \"**/(node_modules|test|doc)/**/*\" .",
    "doc3": "typedoc --theme markdown --out ./docs --ignoreCompilerErrors .",
    "test": "npx mocha \"!(node_modules)\\**\\*.+(test|spec).js\""
  },

they all print

> typedoc --theme markdown --out ./docs --ignoreCompilerErrors .

Loaded plugin typedoc-plugin-markdown

Using TypeScript 2.7.1 from node_modules\typescript\lib
Error: node_modules/@types/node/index.d.ts(41)
 Cannot redeclare block-scoped variable 'Error'.
Error: node_modules/@types/node/index.d.ts(80)
 Cannot redeclare block-scoped variable 'String'.
Error: node_modules/typescript/lib/lib.d.ts(24)
 Cannot redeclare block-scoped variable 'NaN'.
Error: node_modules/typescript/lib/lib.d.ts(25)
 Cannot redeclare block-scoped variable 'Infinity'.
Error: node_modules/typescript/lib/lib.es2018.full.d.ts(15467)
 Duplicate identifier 'VisibilityState'.
Error: node_modules/typescript/lib/lib.es2018.full.d.ts(15468)
 Duplicate identifier 'XMLHttpRequestResponseType'.
Error: node_modules/typescript/lib/lib.es2018.full.d.ts(15684)
 Duplicate identifier 'SafeArray'.
Error: node_modules/typescript/lib/lib.es2018.full.d.ts(15768)
 Duplicate identifier 'VarDate'.
Error: node_modules/typescript/lib/lib.es2018.full.d.ts(15777)
 Cannot redeclare block-scoped variable 'Date'.
Error: node_modules/typescript/lib/lib.es5.d.ts(24)
 Cannot redeclare block-scoped variable 'NaN'.
Error: node_modules/typescript/lib/lib.es5.d.ts(25)
 Cannot redeclare block-scoped variable 'Infinity'.
Error: node_modules/typescript/lib/lib.es5.d.ts(4076)
 Cannot redeclare block-scoped variable 'String'.
Error: node_modules/typescript/lib/lib.es5.d.ts(4086)
 Cannot redeclare block-scoped variable 'Number'.
Error: node_modules/typescript/lib/lib.es5.d.ts(4095)
 Cannot redeclare block-scoped variable 'Date'.
Error: node_modules/typescript/lib/lib.es6.d.ts(24)
 Cannot redeclare block-scoped variable 'NaN'.
Error: node_modules/typescript/lib/lib.es6.d.ts(25)
 Cannot redeclare block-scoped variable 'Infinity'.
Error: node_modules/typescript/lib/lib.es6.d.ts(106)
 Duplicate string index signature.
Error: node_modules/typescript/lib/lib.es6.d.ts(109)
 Cannot redeclare block-scoped variable 'Object'.
Error: node_modules/typescript/lib/lib.es6.d.ts(256)
 Cannot redeclare block-scoped variable 'Object'.
Error: node_modules/typescript/lib/lib.es6.d.ts(261)
 Cannot redeclare block-scoped variable 'Function'.
Error: node_modules/typescript/lib/lib.es6.d.ts(305)
 Cannot redeclare block-scoped variable 'Function'.
Error: node_modules/typescript/lib/lib.es6.d.ts(308)
 Duplicate number index signature.
Error: node_modules/typescript/lib/lib.es6.d.ts(313)
 Cannot redeclare block-scoped variable 'String'.
Error: node_modules/typescript/lib/lib.es6.d.ts(446)
 Cannot redeclare block-scoped variable 'String'.
Error: node_modules/typescript/lib/lib.es6.d.ts(448)
 Cannot redeclare block-scoped variable 'Boolean'.
Error: node_modules/typescript/lib/lib.es6.d.ts(459)
 Cannot redeclare block-scoped variable 'Boolean'.
Error: node_modules/typescript/lib/lib.es6.d.ts(461)
 Cannot redeclare block-scoped variable 'Number'.
Error: node_modules/typescript/lib/lib.es6.d.ts(521)
 Cannot redeclare block-scoped variable 'Number'.
Error: node_modules/typescript/lib/lib.es6.d.ts(527)
 Cannot redeclare block-scoped variable 'Math'.
Error: node_modules/typescript/lib/lib.es6.d.ts(636)
 Cannot redeclare block-scoped variable 'Math'.
Error: node_modules/typescript/lib/lib.es6.d.ts(639)
 Cannot redeclare block-scoped variable 'Date'.
Error: node_modules/typescript/lib/lib.es6.d.ts(818)
 Cannot redeclare block-scoped variable 'Date'.
Error: node_modules/typescript/lib/lib.esnext.full.d.ts(15466)
 Duplicate identifier 'ScopedCredentialType'.
Error: node_modules/typescript/lib/lib.esnext.full.d.ts(15467)
 Duplicate identifier 'ServiceWorkerState'.
Error: node_modules/typescript/lib/lib.esnext.full.d.ts(15468)
 Duplicate identifier 'Transport'.
Error: node_modules/typescript/lib/lib.esnext.full.d.ts(15469)
 Duplicate identifier 'VideoFacingModeEnum'.
Error: node_modules/typescript/lib/lib.esnext.full.d.ts(15470)
 Duplicate identifier 'VisibilityState'.
Error: node_modules/typescript/lib/lib.esnext.full.d.ts(15471)
 Duplicate identifier 'XMLHttpRequestResponseType'.
Error: node_modules/typescript/lib/lib.esnext.full.d.ts(15687)
 Duplicate identifier 'SafeArray'.
Error: node_modules/typescript/lib/lib.esnext.full.d.ts(15771)
 Duplicate identifier 'VarDate'.
Error: node_modules/typescript/lib/lib.scripthost.d.ts(226)
 Duplicate identifier 'SafeArray'.
Error: node_modules/typescript/lib/lib.scripthost.d.ts(310)
 Duplicate identifier 'VarDate'.
Error: node_modules/typescript/lib/lib.webworker.d.ts(1968)
 Duplicate identifier 'ResponseType'.
Error: node_modules/typescript/lib/lib.webworker.d.ts(1969)
 Duplicate identifier 'ServiceWorkerState'.
Error: node_modules/typescript/lib/lib.webworker.d.ts(1970)
 Duplicate identifier 'VisibilityState'.
Error: node_modules/typescript/lib/lib.webworker.d.ts(1971)
 Duplicate identifier 'XMLHttpRequestResponseType'.
Error: test/_local-dev.d.ts(0)
 Cannot find module 'chai'.
Error: test/_local-dev.d.ts(1)
 Cannot find module 'chai'.


Documentation generated at 


Process finished with exit code 0

Edited to shorten comment

bluelovers avatar Feb 17 '18 04:02 bluelovers

Add: "skipLibCheck": true to tsconfig.json compilerOptions.

alexisbg avatar Jun 06 '18 19:06 alexisbg

I did not have success with any of the proposed solutions here. My specific issue is with @types/bluebird:

...myProject/node_modules/@types/sequelize/node_modules/@types/bluebird/index.d.ts(944)

(of course the --ignoreCompilerErrors works, but that seems wrong. It might skip real issues.)

stephan-nordnes-eriksen avatar Aug 17 '18 12:08 stephan-nordnes-eriksen

Same issue here, none-of the proposed solutions have worked for me, and I am on the latest v0.13.0 as of writing this.

I'm just trying to generate json and it's including all of the node_modules .d.ts files in there. For now I'm just dealing with it, the other thing is that the node_modules get absolute paths. So I've got a script to transform all of the fileName paths from absolute to relative in the exported jsonFile. I wouldn't need that script and the output would be much faster/smaller if node_modules could actually be ignored.

StJohn3D avatar Oct 15 '18 20:10 StJohn3D

Here's an overview of how the exclude option works now, and a few notes on potential issues with changing it.

  1. User runs typedoc [options] <files/dirs>

  2. files/dirs are expanded by Application.expandInputFiles

  3. The expanded array of files is passed to ts.createProgram in the Converter.convert function.

  4. TypeScript (not TypeDoc!) resolves any dependencies which are not included in the input files, and loads typing files. By default, this includes all .d.ts files under node_modules/@types.

    It's important to note that this is expected behavior. TypeScript needs those files in order to correctly type the files we provided. Without it, you would likely end up with a lot of any showing up in your docs.

  5. TypeDoc then loops over all project source files, without filtering according to the exclude array. This is what is causing the unexpected behavior here.

The obvious fix is to filter source files based on the exclude pattern... but this raises a few more issues.

  1. We need to silently ignore any errors in files that are excluded... but what should be done about errors that are caused by misusing an imported type in an ignored file?
  2. What happens when we reference a type from an excluded file? Just printing the type name doesn't really help anyone trying to read the docs.

Gerrit0 avatar Nov 01 '18 16:11 Gerrit0

Add: "skipLibCheck": true to tsconfig.json compilerOptions.

Still working with TypeDoc version 0.25.6

agfe2silver avatar Jan 05 '24 09:01 agfe2silver