plate icon indicating copy to clipboard operation
plate copied to clipboard

Running a jest test generates `Cannot find module '@udecode/plate-core/server'` error

Open TrySpace opened this issue 1 year ago • 4 comments

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'

plate fial

Environment

  • "@udecode/plate": "^33.0.6",
  • "@udecode/plate-common": "^33.0.4",
  • "slate": "^0.103.0",
  • "slate-react": "^0.104.0",

TrySpace avatar May 26 '24 10:05 TrySpace

Hey @TrySpace, Did you find any solution around it? I'm facing same issue.

ns-harshp avatar Jun 04 '24 10:06 ns-harshp

No, I've disabled the test for now 🤷🏻

TrySpace avatar Jun 04 '24 10:06 TrySpace

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

reactima avatar Jul 02 '24 21:07 reactima

We upgraded Jest from version 27.2 to the latest stable version (29.7) and it fixed the issue above.

ECecillo avatar Jul 10 '24 15:07 ECecillo

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",

caspersf avatar Sep 27 '24 07:09 caspersf

Use module: bundler in tsconfig

zbeyens avatar Sep 27 '24 09:09 zbeyens

Would someone be able to explain the root cause of the issue for me? I'm still running into it unfortunately.

nicholasjativa avatar Oct 02 '24 00:10 nicholasjativa

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`

linonetwo avatar Oct 17 '24 13:10 linonetwo

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?

shaurya157 avatar Oct 26 '24 19:10 shaurya157

updating the tsconfig to "

compilerOptions": { 
    "moduleResolution": "bundler",

...
} 

worked for me

bbyiringiro avatar Nov 06 '24 13:11 bbyiringiro