mozilla / sphinx-js

Autodoc-style extraction into Sphinx for your JS project
https://pypi.python.org/pypi/sphinx-js/
MIT License
282 stars 81 forks source link

Extension Error (exception: 'sources') #166

Open zapfdk opened 3 years ago

zapfdk commented 3 years ago

Hi, I'm trying to build Typescript documentation, but I'm getting this error when executing make html SPHINXOPTS=-v (local paths replaced with $env_path for privacy):

Traceback (most recent call last):
  File "$env_path/lib/python3.8/site-packages/sphinx/events.py", line 110, in emit
    results.append(listener.handler(self.app, *args))
  File "$env_path/lib/python3.8/site-packages/sphinx_js/__init__.py", line 60, in analyze
    app._sphinxjs_analyzer = analyzer.from_disk(abs_source_paths,
  File "$env_path/lib/python3.8/site-packages/sphinx_js/typedoc.py", line 40, in from_disk
    return cls(json, base_dir)
  File "$env_path/lib/python3.8/site-packages/sphinx_js/typedoc.py", line 29, in __init__
    ir_objects = self._convert_all_nodes(json)
  File "$env_path/lib/python3.8/site-packages/sphinx_js/typedoc.py", line 113, in _convert_all_nodes
    converted, more_todo = self._convert_node(todo.pop())
  File "$env_path//lib/python3.8/site-packages/sphinx_js/typedoc.py", line 154, in _convert_node
    constructor, members = self._constructor_and_members(node)
  File "$env_path/lib/python3.8/site-packages/sphinx_js/typedoc.py", line 100, in _constructor_and_members
    ir, _ = self._convert_node(child)
  File "$env_path/lib/python3.8/site-packages/sphinx_js/typedoc.py", line 190, in _convert_node
    first_sig['sources'] = node['sources']
KeyError: 'sources'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "$env_path/lib/python3.8/site-packages/sphinx/cmd/build.py", line 276, in build_main
    app = Sphinx(args.sourcedir, args.confdir, args.outputdir,
  File "$env_path/lib/python3.8/site-packages/sphinx/application.py", line 278, in __init__
    self._init_builder()
  File "$env_path/lib/python3.8/site-packages/sphinx/application.py", line 337, in _init_builder
    self.events.emit('builder-inited')
  File "$env_path/lib/python3.8/site-packages/sphinx/events.py", line 117, in emit
    raise ExtensionError(__("Handler %r for event %r threw an exception") %
sphinx.errors.ExtensionError: Handler <function analyze at 0x7f0ca88759d0> for event 'builder-inited' threw an exception (exception: 'sources')

Extension error:
Handler <function analyze at 0x7f0ca88759d0> for event 'builder-inited' threw an exception (exception: 'sources')

Versions: TypeDoc 0.20.14 Using TypeScript 4.1.3 from /usr/lib/node_modules/typescript/lib Sphinx 3.4.3 Sphinx-js 3.1

I tried debugging, but I'm new to typedoc, so I'm kind of stuck. What I could tell was that it crashes when processing the constructor of my class, in typedoc.py kind == Constructor

Any idea where this is coming from?

erikrose commented 3 years ago

It sounds like TypeDoc's JSON format has changed again. Can you try on TypeDoc 0.15.0 and see if it works? We're known to be compatible with that version (and working on future versions: see #162).

zapfdk commented 3 years ago

With TypeDoc 0.15.0 (which downgrades Typescript to 3.5.3. and highlight.js to 9.18.5, I receive this error message:


Using TypeScript 3.5.3 from /usr/lib/node_modules/typedoc/node_modules/typescript/lib
Error: $imported_file_path.ts(0)
 Cannot use imports, exports, or module augmentations when '--module' is 'none'.

Traceback (most recent call last):
  File "$env_path/lib/python3.8/site-packages/sphinx/events.py", line 110, in emit
    results.append(listener.handler(self.app, *args))
  File "$env_path/lib/python3.8/site-packages/sphinx_js/__init__.py", line 60, in analyze
    app._sphinxjs_analyzer = analyzer.from_disk(abs_source_paths,
  File "$env_path/lib/python3.8/site-packages/sphinx_js/typedoc.py", line 37, in from_disk
    json = typedoc_output(abs_source_paths,
  File "$env_path/lib/python3.8/site-packages/sphinx_js/typedoc.py", line 331, in typedoc_output
    return load(getreader('utf-8')(temp))
  File "$home_path/.pyenv/versions/3.8.6/lib/python3.8/json/__init__.py", line 293, in load
    return loads(fp.read(),
  File "$home_path/.pyenv/versions/3.8.6/lib/python3.8/json/__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "$home_path/.pyenv/versions/3.8.6/lib/python3.8/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "$home_path/.pyenv/versions/3.8.6/lib/python3.8/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "$env_path/lib/python3.8/site-packages/sphinx/cmd/build.py", line 276, in build_main
    app = Sphinx(args.sourcedir, args.confdir, args.outputdir,
  File "$env_path/lib/python3.8/site-packages/sphinx/application.py", line 278, in __init__
    self._init_builder()
  File "$env_path/lib/python3.8/site-packages/sphinx/application.py", line 337, in _init_builder
    self.events.emit('builder-inited')
  File "$env_path/lib/python3.8/site-packages/sphinx/events.py", line 117, in emit
    raise ExtensionError(__("Handler %r for event %r threw an exception") %
sphinx.errors.ExtensionError: Handler <function analyze at 0x7f10265c49d0> for event 'builder-inited' threw an exception (exception: Expecting value: line 1 column 1 (char 0))

Extension error:
Handler <function analyze at 0x7f10265c49d0> for event 'builder-inited' threw an exception (exception: Expecting value: line 1 column 1 (char 0))

module is set to "commonjs" in tsconfig.json

In $imported_file_path, I'm importing another library file with import * from "./other_file.js" which again imports * from crypto.

erikrose commented 3 years ago

Well, I don't know what the heck any of that means, but it doesn't look good! :-) Hopefully when we get around to updating for newer versions of typedoc, it'll fix this.

pretentious7 commented 3 years ago

I had this error recently, fixed it by changing

js_source_path = '../../$SRC_FOLDER' to js_source_path = '../../$SRC_FOLDER/$SRC_FILE'

but this of course doesn't seem to work when setting js_source_path to a list of things.

wolfviking0 commented 3 years ago

Hi Guys, regarding this problem I understand where is the issue but not sure the exact way to fix it.

Inside https://github.com/mozilla/sphinx-js/blob/a1ee45651f14bba63a4e2e370e9acadc847c017b/sphinx_js/typedoc.py#L197 the node['sources'] seems to be invalid when the kind is Constructor.

Gallaecio commented 2 years ago

Minimal, reproducible example with TypeDoc 0.22.15:

$ cat conf.py 
exclude_patterns = [
    'venv',
]
extensions = [
    'sphinx_js',
]
js_language = 'typescript'
js_source_path = '.'
jsdoc_config_path = 'tsconfig.json'
$ cat index.ts 
export class Foo {}
$ cat tsconfig.json 
{"compilerOptions": {"lib": ["dom", "es2018"]}, "entryPoints": ["index.ts"]}
$ touch index.rst
$ python3 -m venv venv
$ . venv/bin/activate
(venv) $ pip install sphinx git+https://github.com/mozilla/sphinx-js.git
…
Successfully installed … sphinx-5.1.1 sphinx-js-3.1.2 …
…
(venv) $ sphinx-build -b html -v . _build
…
Traceback (most recent call last):
  File "<working directory>/venv/lib/python3.9/site-packages/sphinx/events.py", line 94, in emit
    results.append(listener.handler(self.app, *args))
  File "<working directory>/venv/lib/python3.9/site-packages/sphinx_js/__init__.py", line 61, in analyze
    app._sphinxjs_analyzer = analyzer.from_disk(abs_source_paths,
  File "<working directory>/venv/lib/python3.9/site-packages/sphinx_js/typedoc.py", line 41, in from_disk
    return cls(json, base_dir)
  File "<working directory>/venv/lib/python3.9/site-packages/sphinx_js/typedoc.py", line 30, in __init__
    ir_objects = self._convert_all_nodes(json)
  File "<working directory>/venv/lib/python3.9/site-packages/sphinx_js/typedoc.py", line 142, in _convert_all_nodes
    converted, more_todo = self._convert_node(todo.pop())
  File "<working directory>/venv/lib/python3.9/site-packages/sphinx_js/typedoc.py", line 183, in _convert_node
    constructor, members = self._constructor_and_members(node)
  File "<working directory>/venv/lib/python3.9/site-packages/sphinx_js/typedoc.py", line 129, in _constructor_and_members
    ir, _ = self._convert_node(child)
  File "<working directory>/venv/lib/python3.9/site-packages/sphinx_js/typedoc.py", line 219, in _convert_node
    first_sig['sources'] = node['sources']
KeyError: 'sources'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<working directory>/venv/lib/python3.9/site-packages/sphinx/cmd/build.py", line 272, in build_main
    app = Sphinx(args.sourcedir, args.confdir, args.outputdir,
  File "<working directory>/venv/lib/python3.9/site-packages/sphinx/application.py", line 261, in __init__
    self._init_builder()
  File "<working directory>/venv/lib/python3.9/site-packages/sphinx/application.py", line 334, in _init_builder
    self.events.emit('builder-inited')
  File "<working directory>/venv/lib/python3.9/site-packages/sphinx/events.py", line 105, in emit
    raise ExtensionError(__("Handler %r for event %r threw an exception") %
sphinx.errors.ExtensionError: Handler <function analyze at 0x7f2e80dd4ee0> for event 'builder-inited' threw an exception (exception: 'sources')

Extension error (sphinx_js):
Handler <function analyze at 0x7f2e80dd4ee0> for event 'builder-inited' threw an exception (exception: 'sources')
Gallaecio commented 2 years ago

I can get it to work with 0.16.11 (0.17.0 is the breaking point), avoiding https://github.com/mozilla/sphinx-js/issues/166#issuecomment-758079090, by including module in tsconfig.json.

That is, my minimal example works after the following changes: