sibiraj-s / ngx-editor

🖋️ Rich Text Editor for angular using ProseMirror
https://sibiraj-s.github.io/ngx-editor/
MIT License
457 stars 191 forks source link

[Bug]: Build fails with Yarn #514

Closed jecraig closed 6 months ago

jecraig commented 10 months ago

What happened?

Type conflict when using Yarn. It appears to be an issue with prosemirror-view types. The issue doesn't happen with npm.

Tested with Yarn 4 and Yarn 1.22, both errored.

Version

v16.0.1

Angular Version

v16.2.12

What browsers are you seeing the problem on?

Firefox, Chrome

Link to reproduce

https://github.com/jecraig/ngxeditor-yarn-example

Relevant log output

yarn run build
✔ Browser application bundle generation complete.

Error: node_modules/ngx-editor/node_modules/prosemirror-view/dist/index.d.ts:215:9 - error TS2717: Subsequent property declarations must have the same type.  Property 'pmViewDesc' must be of type 'ViewDesc | undefined', but here has type 'ViewDesc | undefined'.

215         pmViewDesc?: ViewDesc;
            ~~~~~~~~~~

  node_modules/prosemirror-view/dist/index.d.ts:217:9
    217         pmViewDesc?: ViewDesc;
                ~~~~~~~~~~
    'pmViewDesc' was also declared here.

Willing to submit a PR?

None

sibiraj-s commented 10 months ago

Please refer https://github.com/sibiraj-s/ngx-editor/issues/469#issuecomment-1636771997

jecraig commented 10 months ago

Hmm, I've tried that and then some. Even went to the point of installing it fresh on a new angular project and got this issue.

I'll try sending this on towards the Yarn team.

sibiraj-s commented 10 months ago

Oh.

I don't use Yarn. not sure whats happening there. Open to improvements.

jecraig commented 10 months ago

Looking into it more but this appears to be the culprit of the conflicting types. For some reason, prosemirror-view and prosemirror-model are embedded in the yarn install in addition to the lifted folder copy. I don't have an idea on the reason yet but I figured I'd update in case anyone else has an idea.

NPM Left - Yarn Right

image image

jecraig commented 10 months ago

@sibiraj-s The issue is with version resolution. The ngx-editor package is requiring prosemirror-view 1.31.7, but something else requires version 1.32.7. So yarn installs a local package to ngx-editor and the higher version to the root node_modules folder. A similar issue happens with prosemirror-model where ngx-editor wants 1.19.3 but the root also needs to install 1.19.4.

Changing the semantic versioning in projects/ngx-editor/package.json to carets instead of fixed versions resolves the conflict.

jecraig commented 10 months ago

To everyone else, as a temporary workaround you can add the following to your package.json to force the resolution.

"resolutions": {
        "prosemirror-commands": "^1.5.2",
        "prosemirror-history": "^1.3.2",
        "prosemirror-inputrules": "^1.2.1",
        "prosemirror-keymap": "^1.2.2",
        "prosemirror-model": "^1.19.3",
        "prosemirror-schema-list": "^1.3.0",
        "prosemirror-state": "^1.4.3",
        "prosemirror-view": "^1.31.7"
    },

@jakyle this should directly solve your issue in https://github.com/sibiraj-s/ngx-editor/issues/469

sibiraj-s commented 10 months ago

but something else requires version 1.32.7.

This is possible because of one of the Prosemirror package doesn't pin its dependency.

Changing the semantic versioning in projects/ngx-editor/package.json to carets instead of fixed versions resolves the conflict. In the past it was like this, when caret is used, during either angular version or the editor version updates. Some version mismatch often happens. I've pinned the dependency directly dependency to avoid this issue, if not pinned this same issue would become at-least 10x more frequent, during version updates.

Also, it was the time when Prosemirror was made stable initially and it was breaking things often. Its been a while since stable, thinking if I should put it to caret again. Not sure.

jecraig commented 10 months ago

Fortunately Yarn does provide a method to solve this by forcing the decency resolutions. If you decide not to open up semantic versioning then perhaps a note about fixing resolution conflicts in the Yarn section of the docs.

sibiraj-s commented 10 months ago

Yeah. Thanks will mention them in docs. I'll try open up semver if possible, because it also makes me to release new version for each updates.

sibiraj-s commented 6 months ago

Fixed in v17.1.0. dependencies are no longer pinned

github-actions[bot] commented 5 months ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in the thread.