It's my typedoc.json file
{
"inputFiles": ["./src"],
"mode": "modules",
"out": "docs",
"ignoreCompilerErrors": true,
"disableOutputCheck": true,
"excludeExternals": true,
"excludePrivate": true,
"excludeNotExported": true
}
What can I do to use search
Check your browser console when trying to load search - are some errors showing up? Search should be enabled by default.
It says search.js 404.
Here's my config:
"typedocOptions": {
"excludeExternals": true,
"excludeNotExported": true,
"excludePrivate": true,
"excludeProtected": true,
"inputFiles": "src",
"out": "docs"
},
search.js isn't used anymore in 0.17.4, it should be looking for search.json. What version of typedoc-default-themes are you building with?
I have installed typedoc-default-themes specifically. I'm using "typedoc": "^0.17.4". And I've checked that it indeed has installed 0.17.4.
If you run npm ls typedoc-default-themes, is the version 0.10.1?
npm ls --depth=1
...
โโโฌ [email protected]
โ โโโ [email protected]
โ โโโ [email protected]
โ โโโ [email protected]
โ โโโ [email protected] deduped
โ โโโ [email protected]
โ โโโ [email protected]
โ โโโ [email protected] deduped
โ โโโ [email protected] deduped
โ โโโ [email protected]
โ โโโ [email protected]
โโโ [email protected]
...
Try serving de docs with something like https://www.npmjs.com/package/serve
npx serve docs
The search component is doing a fetch, and on the other hand the search.js file is being injected with document.write (even in 0.10.1). This is only done for file:// protocol, which suggests you might just be opening the html without a server, but then fetch may not work (chrome only allows it in http or https).
It's a theme problem. I swap it out and if works fine. Sorry for the mess.
Is there a strong reason for the removal of this search.js? Being able to open the files directly in my browser is a quick way to make sure the pages load as expected. I don't know how much work it is to maintain it, but it seems like it introduces friction to have to spin up a server just to load what would otherwise be static HTML files.
Good question, I believe @sgrishchenko's original motivation was to reduce the possibility for code injection. As a part of the transition to JSON, it also improved the page load speed by doing indexing when building the docs rather than whenever anyone loaded the page. The latter is more important to me than storing it in a JSON file, and I agree that it would be nice to be able to use the docs without starting a server... I'd be open to reverting to a JS file.
@Fleker Sorry, but I don't understand why we should use JavaScript to transfer static data? If you want use brouser preview, you can use json file the same way, here the screen of json from my documentation site (https://sgrishchenko.github.io/reselect-utils/typedoc/light/assets/js/search.json). It works fine for me.

@sgrishchenko that approach works fine when you are hosting the files on GitHub or some other server, but it does not work if you try to open the files locally file:///usr/.../docs/index.html, where I get the error:
main.js:6 Fetch API cannot load file:///usr/.../docs/assets/js/search.json. URL scheme must be "http" or "https" for CORS request.
Unless I take the advice above and have to spin up a local server using npx serve docs.
Having an improvement in speed is definitely beneficial, but being able to run locally through some fallback behavior would still be useful.
The theme default.hbs previously had the line:
<script>if (location.protocol == 'file:') document.write('<script src="{{relativeURL "assets/js/search.js"}}"><' + '/script>');</script>
which could return to provide some sort of substitute implementation when the script is activated.
@Fleker Oh, now I see, thank you, but it looks like a hack for me. What if tomorrow Google Chrome or Firefox says that JS files should be loaded via "http" or "https" too? Shall we explore another hack to make workaround for this case?
@Fleker But may be it is not bad to make some hacks to improve DX, maybe it will be better to have two modes: development and production. JS will be used in development mode and JSON - in production. Or maybe typedoc should start up some development server (e.g. webpack-dev-server) like CRA or Storybook does.
If Chrome or Firefox implemented a particular limitation, then it'd probably make sense for Typedoc to make another workaround as Typedoc is built for web browsers and are tied to platform requirements.
Having a development mode, which would be functionally the same as production, would be beneficial in trying out the doc rendering quickly.
Most helpful comment
Try serving de docs with something like https://www.npmjs.com/package/serve
npx serve docsThe search component is doing a fetch, and on the other hand the search.js file is being injected with
document.write(even in 0.10.1). This is only done forfile:// protocol, which suggests you might just be opening the html without a server, but then fetch may not work (chrome only allows it in http or https).