Running a jest test generates `Cannot find module '@udecode/plate-core/server'` error
Description
When running a jest test which includes imports from @udecode/plate-common generates the error Cannot find module '@udecode/plate-core/server'
Cannot find module '@udecode/plate-core/server' from 'node_modules/@udecode/plate-utils/dist/index.js'
Steps to Reproduce
Jest doesn't clearly say which import it is but it's one of the imports from the shared MyPlateEditor.types file:
import {
EDescendant,
EElement,
EElementEntry,
EElementOrText,
EMarks,
ENode,
ENodeEntry,
EText,
ETextEntry,
TElement,
TNodeEntry,
TReactEditor,
createTEditor,
getTEditor,
} from '@udecode/plate-common'
Environment
- "@udecode/plate": "^33.0.6",
- "@udecode/plate-common": "^33.0.4",
- "slate": "^0.103.0",
- "slate-react": "^0.104.0",
Hey @TrySpace, Did you find any solution around it? I'm facing same issue.
No, I've disabled the test for now 🤷🏻
Please kindly fix this issue.
This might related to misconfigured imports in
src/packages/slate-plate/common/src/server.ts src/packages/slate-plate/common/src/index.tsx
I have a wild tsconfig and cach deps and see messages like this
TS2305: Module "@udecode/plate-core/server" has no exported member applyDeepToNodes
We upgraded Jest from version 27.2 to the latest stable version (29.7) and it fixed the issue above.
Hey @zbeyens, @12joan
I am still facing this issue on upgrading my packages.
Environment
- "@udecode/plate-common": "^36.5.8",
- "@udecode/plate-core": "^36.5.8",
- "slate": "^0.103.0",
- "slate-history": "^0.100.0",
- "slate-hyperscript": "^0.100.0",
- "slate-react": "^0.102.0",
- "jest": "^29.7.0",
- "typescript": "^4.8.4",
- "react": "^16.8.6",
- "react-dom": "^16.8.6",
Use module: bundler in tsconfig
Would someone be able to explain the root cause of the issue for me? I'm still running into it unfortunately.
I find it in compiled code, it is @udecode/plate-paragraph 's fault. And it appear on client side on my project, cause project not loading.
// node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected]._jmvojqtwwvjkatn57nueqrsl2u/node_modules/@udecode/plate-paragraph/dist/index.mjs
init_esbuild_inject();
var import_server = require("@udecode/plate-common/server");
var ELEMENT_PARAGRAPH = "p";
var createParagraphPlugin = (0, import_server.createPluginFactory)({
deserializeHtml: {
query: (el) => el.style.fontFamily !== "Consolas",
to fix, delete
import { ELEMENT_PARAGRAPH } from '@udecode/plate-paragraph';
replace with this
import { ParagraphPlugin } from '@udecode/plate-core/react';
// use `ParagraphPlugin.key`
to fix, delete
import { ELEMENT_PARAGRAPH } from '@udecode/plate-paragraph';
replace with this
I tried this, doesn't work for me... anyone able to resolve this?
updating the tsconfig to "
compilerOptions": {
"moduleResolution": "bundler",
...
}
worked for me