Typings import `react` but `@types/react` is not declared as a peer dependency
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 62/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- react, typescript
- Domain
- build-system, frontend
Research direction
The fix is in package.json, where peerDependencies lists react, react-dom and tinymce but not @types/react. The published typings in lib/es2015/main/ts/components/Editor.d.ts import from react, which is why the declaration is needed. Reproduce with the linked repo using pnpm install and pnpm typecheck, with enableGlobalVirtualStore set to true. Done when the optional @types/react peer is declared and the typecheck passes under that setting.
Written by the indexing model from the issue text.
Description
What is the current behavior?
The published typings import from react (for example lib/es2015/main/ts/components/Editor.d.ts), but package.json doesn't declare @types/react anywhere. The peer dependencies are only react, react-dom and tinymce.
This usually works by accident because @types/react is hoisted somewhere above the package in node_modules. It fails under package managers that only let a package see what it declares. With pnpm's global virtual store (enableGlobalVirtualStore: true), each package is linked from a shared directory outside the project, so TypeScript can't find @types/react from inside @tinymce/tinymce-react. Editor then stops typechecking as a React component:
src/App.tsx(4,10): error TS2607: JSX element class does not support attributes because it does not have a 'props' property.
src/App.tsx(4,11): error TS2786: 'Editor' cannot be used as a JSX component.
Its type 'typeof Editor' is not a valid JSX element type.
Type 'typeof Editor' is not assignable to type 'new (props: any, context: any) => Component<any, any, any>'.
Type 'Editor' is missing the following properties from type 'Component<any, any, any>': context, setState, forceUpdate, props, state
This is a different cause from https://github.com/tinymce/tinymce-react/issues/332. That issue was two mismatched @types/react versions, while here the package can't resolve @types/react at all.
Please provide the steps to reproduce and if possible a minimal demo of the problem via codesandbox.io or similar.
Minimal reproduction: https://github.com/joeymckenzie/tinymce-react-types-react-repro
pnpm install
pnpm typecheck
src/App.tsx is just:
import { Editor } from "@tinymce/tinymce-react";
export function App() {
return <Editor licenseKey="gpl" initialValue="<p>Hello</p>" />;
}
With the same lockfile and enableGlobalVirtualStore: false, tsc passes.
What is the expected behavior?
Editor typechecks without relying on @types/react being hoisted. Declaring it as an optional peer would do that and keep sharing the consumer's copy:
"peerDependencies": {
"@types/react": "^19.0.0 || ^18.0.0 || ^17.0.0 || ^16.7.0"
},
"peerDependenciesMeta": {
"@types/react": { "optional": true }
}
Our workaround in the meantime is declaring it on the package's behalf in pnpm-workspace.yaml:
packageExtensions:
"@tinymce/tinymce-react":
peerDependencies:
"@types/react": "*"
peerDependenciesMeta:
"@types/react":
optional: true
Which versions of TinyMCE, and which browser / OS are affected by this issue? Did this work in previous versions of TinyMCE or tinymce-react?
@tinymce/tinymce-react 6.3.0
- Dominant language
- TypeScript
- Stars
- 1.1k
- Forks
- 167
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from tinymce/tinymce-react
-
smart_paste doesn't detected pasted urls as linkPossibly taken @hardikpedia claimed this 50 days ago. Openstatus: escalated
Difficulty 3/5 1-2 days Newbie friendliness 55/100
tinymce/tinymce-react#611 · 1 comment ·
-
needs: more info
Difficulty 4/5 3-5 days Newbie friendliness 20/100
tinymce/tinymce-react#595 · 1 comment ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
tinymce/tinymce-react#587 · 15 comments · 3 reactions ·
-
GitHub status: escalated
Difficulty 3/5 1-2 days Newbie friendliness 25/100
tinymce/tinymce-react#501 · 5 comments · 8 reactions ·
-
bug GitHub status: escalated
Difficulty 4/5 3-5 days Newbie friendliness 25/100
tinymce/tinymce-react#403 · 5 comments · 1 reaction ·
All issues in tinymce/tinymce-react
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
tenstorrent/ttnn-visualizer#2526 ·
Maintainers usually reply within 1 day
-
trySessionCache calls /get-session twice when minting session_data (cache miss or expired cookie)Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
neondatabase/neon-js#301 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
tashfeenahmed/freellmapi#2305 ·
Maintainers usually reply within 1 day