Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package.json exports restriction breaks external plugins #1696

Closed
mf-pherlihy opened this issue Sep 13, 2021 · 5 comments
Closed

Package.json exports restriction breaks external plugins #1696

mf-pherlihy opened this issue Sep 13, 2021 · 5 comments
Labels
enhancement Improved functionality

Comments

@mf-pherlihy
Copy link

Search Terms

  • exports
  • is not defined by "exports"
  • Package subpath

Problem

Prior to 0.22.0, you could import specific TypeDoc classes and functions that made plugin development simpler:

import { MarkdownEvent } from 'typedoc/dist/lib/output/events';
import { getRawComment } from 'typedoc/dist/lib/converter/factories/comment';

this.app.listenTo(
  this.app.renderer,
  MarkdownEvent.PARSE,
  (event: MarkdownEvent) => someHandler(event),
  eventPriority
);

However, in the 0.22.0 release a change was made to package.json which no longer allows this: 4f33ff8

"exports": "./dist/index.js",

Leading to this error:

Error: Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './dist/lib/output/events' is not defined by "exports"

Suggested Solution

Remove exports from package.json

OR

While tedious, we could add any files that might be useful to external plugins.

@mf-pherlihy mf-pherlihy added the enhancement Improved functionality label Sep 13, 2021
@mf-pherlihy mf-pherlihy changed the title Package.json exports restriction break external plugins Package.json exports restriction breaks external plugins Sep 13, 2021
@FireAndIceFrog
Copy link

I am also getting this problem. I encountered it using typedoc as expected but it throws the same error you are getting.

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './dist/lib/converter' is not defined by "exports"

A solution is to include my version of typedocs package.json to hold a converter reference

image

Obviously this isn't good, so please escalate this issue

@Gerrit0
Copy link
Collaborator

Gerrit0 commented Sep 15, 2021

This change was intentional - if you are using/want to use something that isn't exported, I want to know! Knowing means I can try to avoid breaking your plugin while refactoring, particularly during patch releases, and can better curate the public API.

Exporting MarkdownEvent seems reasonable to me, PR welcome, or I'll probably get to it this weekend. What are you using getRawComment for? Whatever it is, it'll almost certainly break once https://github.com/TypeStrong/typedoc/projects/11 is done, which is likely what I'll be chasing for 0.23.

Everything from converter.ts is exported from the root, so @FireAndIceFrog's problem should be resolved by importing from "typedoc" rather than the internal path.

@SamJakob
Copy link

This change broke our CI (in the exact way reported by @FireAndIceFrog) so I've created a simple 'hot fix' for this until the plugins are updated (though they do look impressively well maintained so I'd imagine that'll probably happen fairly soon).

https://gist.github.com/SamJakob/6fd2f06cc38242557e5d2d50fbe7a157
This simply guides adding a 'post install' script to yarn that replaces package.json in node_modules/typedoc/ with one that doesn't have the exports option present.

(!) Naturally, as the point of this change was to raise an alert if something wasn't exported, if you do intend to use my fix, I encourage you to report an issue you're having before using this fix.

@azatoth
Copy link

azatoth commented Oct 16, 2021

@Gerrit0 Seems this issue can be seen in kamiazya/typedoc-plugin-mermaid#441 as well. Looks like it mostly revolves around usage of Component and ConverterComponent.

@Gerrit0
Copy link
Collaborator

Gerrit0 commented Oct 16, 2021

Plugins should not be using either of those. Both are going to be completely removed from TypeDoc's codebase, probably in 0.23

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improved functionality
Projects
None yet
Development

No branches or pull requests

5 participants