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

Missing "./ckeditor5.css" export in "ckeditor5" package #16638

Closed
nahabi opened this issue Jun 29, 2024 · 12 comments
Closed

Missing "./ckeditor5.css" export in "ckeditor5" package #16638

nahabi opened this issue Jun 29, 2024 · 12 comments
Labels
resolution:resolved This issue was already resolved (e.g. by another ticket). squad:core Issue to be handled by the Core team. type:bug This issue reports a buggy (incorrect) behavior.

Comments

@nahabi
Copy link

nahabi commented Jun 29, 2024

Reproduction steps

  1. Installed packages
  2. Wrote my component

Current behavior

Returns [plugin:vite:import-analysis] Missing "./ckeditor5.css" export in "ckeditor5" package

Expected behavior

For the app to run

Definition of Done

  • Please leave this field for us. We will fill it during the backlog refinement session.

Relevant debug data

import { useState, useEffect, useRef } from 'react'
import { CKEditor } from '@ckeditor/ckeditor5-react'

import {
  ClassicEditor,
  AccessibilityHelp,
  Alignment,
  Autoformat,
  AutoLink,
  Autosave,
  Bold,
  Essentials,
  FindAndReplace,
  Heading,
  Indent,
  IndentBlock,
  Italic,
  Link,
  List,
  Paragraph,
  RemoveFormat,
  SelectAll,
  Table,
  TableToolbar,
  TextTransformation,
  Undo
} from 'ckeditor5'

import 'ckeditor5/ckeditor5.css'

Other details

No response

User agent

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36

@nahabi nahabi added squad:devops Issue to be handled by the Devops team. type:bug This issue reports a buggy (incorrect) behavior. labels Jun 29, 2024
@filipsobol
Copy link
Member

Hi @nahabi,

Are you using the latest versions of ckeditor5 (42.0.0) and @ckeditor/ckeditor5-react (8.0.0)? If so, provide a minimal reproduction so we can investigate.

@filipsobol filipsobol added squad:core Issue to be handled by the Core team. and removed squad:devops Issue to be handled by the Devops team. labels Jun 30, 2024
@nahabi
Copy link
Author

nahabi commented Jun 30, 2024

Please find my dependencies below:

"dependencies": {
    "@chakra-ui/icons": "^2.0.14",
    "@chakra-ui/react": "^2.4.4",
    "@ckeditor/ckeditor5-react": "^8.0.0",
    "@emotion/react": "^11.10.5",
    "@emotion/styled": "^11.10.5",
    "@fontsource/figtree": "^5.0.20",
    "@fontsource/jost": "^4.5.13",
    "@tanstack/react-query": "^4.24.6",
    "@tanstack/react-query-devtools": "^4.24.6",
    "axios": "^1.2.1",
    "axios-hooks": "^4.0.0",
    "ckeditor5": "^42.0.0",
    "date-fns": "^2.29.3",
    "diff": "^5.1.0",
    "dompurify": "^3.1.4",
    "events": "^3.3.0",
    "framer-motion": "^8.0.2",
    "html-react-parser": "^5.1.10",
    "quill": "^2.0.2",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-hook-form": "^7.41.0",
    "react-icons": "^4.7.1",
    "react-quill": "^2.0.0",
    "react-reconciler": "^0.29.0",
    "react-router-dom": "^6.6.0",
    "uuid": "^9.0.0"
  }

And below is the code for the component:

import { CKEditor } from '@ckeditor/ckeditor5-react'
import {
  ClassicEditor,
  Bold,
  Essentials,
  Heading,
  Indent,
  IndentBlock,
  Italic,
  Link,
  List,
  MediaEmbed,
  Paragraph,
  Table,
  Undo
} from 'ckeditor5'

import 'ckeditor5/ckeditor5.css'

const RichCKEditor = ({ data, setData }) => {
  return (
    <CKEditor
      editor={ClassicEditor}
      data={data}
      onChange={(event, editor) => {
        const data = editor.getData()
        setData(data)
      }}
    />
  )
}

export default RichCKEditor

@Witoso
Copy link
Member

Witoso commented Jul 1, 2024

Hey, this looks like some problem with a bundler, in a minimal sample it works correctly: https://stackblitz.com/edit/vitejs-vite-kxuglq?file=src%2Fmain.jsx

Please compare to check if you are not missing something in the setup.

@filipsobol filipsobol changed the title Missing CSS file Missing "./ckeditor5.css" export in "ckeditor5" package Jul 1, 2024
@Witoso Witoso added the pending:feedback This issue is blocked by necessary feedback. label Jul 1, 2024
@bokute2010
Copy link

I have the same issue in nextjs app. Please fix soon.

@CKEditorBot CKEditorBot removed the pending:feedback This issue is blocked by necessary feedback. label Jul 2, 2024
@Witoso
Copy link
Member

Witoso commented Jul 2, 2024

@bokute2010 could you please provide some minimal reproducible sample and version details, we tested the Next.js app setup multiple times with new installation methods, and this was not appearing.

@Reinmar Reinmar added the pending:feedback This issue is blocked by necessary feedback. label Jul 2, 2024
@bokute2010
Copy link

@Witoso
It happening in next 13, no app route. Does ckeditor support older version of nextjs?

@CKEditorBot CKEditorBot removed the pending:feedback This issue is blocked by necessary feedback. label Jul 7, 2024
@filipsobol
Copy link
Member

Could you please provide some minimal reproducible sample?

@filipsobol filipsobol added the pending:feedback This issue is blocked by necessary feedback. label Jul 10, 2024
@YilanBoy
Copy link

YilanBoy commented Jul 16, 2024

I face this problem with vite v2.9.18

➜ npm run build

> build
> vite build

vite v2.9.18 building for production...
✓ 4 modules transformed.
[vite:resolve] Missing "./ckeditor5.css" export in "ckeditor5" package
error during build:
Error: Missing "./ckeditor5.css" export in "ckeditor5" package

Currently, I use relative path to solve this problem.

// Missing "./ckeditor5.css" export in "ckeditor5" package error during build
import 'ckeditor5/ckeditor5.css';
// Pass
import './../../../node_modules/ckeditor5/dist/ckeditor5.css';

In IDE hint, ckeditor5/ckeditor5.css seems correct, but vite can't find the css file.

I found wildcard don't work in vite. there is a issue related to this problem.

  "exports": {

    "...": "..."

    "./ckeditor5.css": "./dist/ckeditor5.css", // add this line can fix the issue
    "./*.css": "./dist/*.css", // but why this line won't wok?

    "...": "..."
  },

@Witoso
Copy link
Member

Witoso commented Jul 16, 2024

As you mentioned, works in Vite from version v4: https://stackblitz.com/edit/gnj9y8?file=index.html,package.json

@filipsobol wdyt about adding additional explicit export, not sure if this is a proper convention.

@YilanBoy
Copy link

After update the vite major version, everything works well. Thanks!

@filipsobol
Copy link
Member

filipsobol commented Jul 16, 2024

As you mentioned, works in Vite from version v4: https://stackblitz.com/edit/gnj9y8?file=index.html,package.json

@filipsobol wdyt about adding additional explicit export, not sure if this is a proper convention.

TLDR: The current implementation of wildcards in the exports field has been supported since Webpack 5.13 (~3.5 years), Vite 4.2 (~1.5 years) and esbuild 0.15.10 (~2 years). Webpack 4 completely ignores it, so the old installation methods work fine. We might be able to make ckeditor5 package work with Vite 2 and 3.


I have tested the current implementation with Vite in versions 2 (❌), 3 (❌), and 4 (✅). At first, the problem seemed to be related to paths containing the * wildcard (subpath patterns). Unfortunately, we use them for other CSS files and translations, build, and src folders.

{
  ".": {
    "types": "./dist/types/index.d.ts",
    "import": "./dist/ckeditor5.js"
  },
  // ⬇️⬇️⬇️
  "./translations/*.js": {
    "types": "./dist/translations/*.d.ts",
    "import": "./dist/translations/*.js"
  },
  "./*.css": "./dist/*.css",
  "./build/*": "./build/*",
  "./src/*": "./src/*",
  // ⬆️⬆️⬆️
  "./package.json": "./package.json"
}

However, in Vite 2 and 3, I was able to load files from the build and src folders, which may indicate that the problem is related to "pattern trailers" (i.e., paths that contain patterns after the wildcard, example:* vs *.css) that were added to Node later than the wildcards themselves (more info).

This needs more testing, but if this is the case, then changing the exports to what is shown below might add support for older versions of Vite.

{
  ".": {
    "types": "./dist/types/index.d.ts",
    "import": "./dist/ckeditor5.js"
  },
  // ⬇️⬇️⬇️
  "./*": "./dist/*",
  "./browser/*": null,
  // ⬆️⬆️⬆️
  "./build/*": "./build/*",
  "./src/*": "./src/*",
  "./package.json": "./package.json"
}

However, if this doesn't work, then we may need to require Vite 4+, because updating the exports field to include all files would make the package.json file huge.


What about webpack 4 and 5?

Wildcard support in the exports field was added 3.5 years ago in webpack 5.13, so we don't need to worry about webpack 5.

Because of this issue, I was worried about webpack 4, which we still support in legacy installation methods. Since exports are exclusive (i.e., paths that are not specified are not accessible), I thought there might be a problem accessing the src or build folder in webpack 4 if the wildcards don't work. Fortunately, this is not the case, as webpack 4 doesn't support the exports field at all, and is able to access all files in the ckeditor5 package as if the exports field were not there.

filipsobol added a commit that referenced this issue Jul 22, 2024
Fix (ckeditor5): Update the `exports` field in `package.json` to fix issues with loading CSS and translations in older bundlers. See #16638.

Internal: Remove the "Lint generated packages" step from CI due to a limitation of the validation library.
@CKEditorBot CKEditorBot added the status:in-progress Set automatically when an issue lands in the "In progress" column. We are working on it. label Jul 22, 2024
pszczesniak added a commit to ckeditor/ckeditor5-package-generator that referenced this issue Jul 22, 2024
Fix (generator): Update the `exports` field in `package.json` templates to fix issues with loading CSS and translations in older bundlers. See ckeditor/ckeditor5#16638.
@filipsobol
Copy link
Member

This problem has been fixed in 42.0.2.

@CKEditorBot CKEditorBot removed the status:in-progress Set automatically when an issue lands in the "In progress" column. We are working on it. label Jul 25, 2024
@Witoso Witoso added resolution:resolved This issue was already resolved (e.g. by another ticket). and removed pending:feedback This issue is blocked by necessary feedback. labels Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
resolution:resolved This issue was already resolved (e.g. by another ticket). squad:core Issue to be handled by the Core team. type:bug This issue reports a buggy (incorrect) behavior.
Projects
None yet
Development

No branches or pull requests

7 participants