-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Cannot combine imports from ckeditor5
with deep imports
#17575
Comments
The // ✔️
import {} from '@ckeditor/ckeditor5-ui/src/editableui/editableuiview.js';
// ^^^ However, the // ✖️
import {} from '@ckeditor/ckeditor5-ui/dist/editableui/editableuiview.js';
// ^^^^ In new installation methods, only the following imports are allowed: import {} from 'ckeditor5';
import {} from '@ckeditor/ckeditor5-ui/dist/index.js'; Unfortunately, it's not possible to import |
@filipsobol @Witoso thanks for your replies. I guess the use of a symbol that isn't exported by The documentation suggests deep imports from Here's perhaps a cleaner example: import { ClassicEditor, Paragraph } from 'ckeditor5';
import type { Plugin } from '@ckeditor/ckeditor5-core/dist/index.js';
const editorConfig = {
plugins: [Paragraph],
licenseKey: 'GPL',
};
function logEnabled(plugin: Plugin) {
console.log('Plugin:', plugin.isEnabled);
}
ClassicEditor.create(document.querySelector('#editor') as HTMLElement, editorConfig).then((editor) => {
let plugin = editor.plugins.get('Paragraph');
logEnabled(plugin);
}); This produces a type error
because Is this intentional? This seems like a bug. |
I see the problem now, and this is not intentional. Thank you for bringing this to our attention. I'll look into it. As a side note, if you want to optimize the build size, all imports should be from the |
@bendemboski Do you use the |
@filipsobol great, glad we're on the same page, and sorry my initial explanation was kinda convoluted. Curious -- what is it about imports through As far as So standby, and hopefully in the next few business days I'll open a new issue for discussion about all of the un-exported symbols we use 👍 |
It's mostly code from external dependencies used in the You can read more about it here: #16395 |
@filipsobol I just filed #17644 that describes why we need |
Consider the following code:
As-is (running against CKEditor 43.3.1), the code produces this type error:
This is because
ckeditor5
resolves to ckeditor5/dist/index.d.ts, which re-exports the contents of@ckeditor/ckeditor5-ui
, which resolves to@ckeditor/ckeditor5-ui/src/index.d.ts
(note that we've "hopped over" fromdist/
directories tosrc/
directories). Since@ckeditor/ckeditor5-ui/dist/index.d.ts
is a copy of@ckeditor/ckeditor5-ui/src/index.d.ts
(rather than re-exporting it), they export different symbols that share the same nameEditorUIView
, resulting in the error above.The type error can be fixed by changing line 2 to
import EditableUIView from '@ckeditor/ckeditor5-ui/src/editableui/editableuiview';
(replacingdist
withsrc
). However, this causes module duplication because while the types inckeditor5
re-export@ckeditor/ckeditor5-ui/src
, the Javascript re-exports@ckeditor/ckeditor5-ui/dist/index.js
. So now the types agree, but the bundled application will include both@ckeditor/ckeditor5-ui/dist/index.js
(from the import viackeditor
) and@ckeditor/ckeditor5-ui/src/editableui/editableuiview.js
(via the deep import), and now at runtime there will be two copies of theEditableUIView
class, inflating the bundle and potentially messing upinstanceof
checks and the like.I just used
@ckeditor/ckeditor5-ui
as an example -- the same issue exists with all the@ckeditor/ckeditor5-*
packages.The fundamental problem here is that
dist
is not isolated fromsrc
, and anytime the module graph "hops over" fromdist
tosrc
, there will likely be a conflict that results in either type errors or module duplication.This also runs deeper than just
ckeditor5/dist/index.d.ts
-- there are many.d.ts
files indist
directories of@ckeditor/ckeditor5-*
packages that import from the module root of other@ckeditor/ckeditor5-*
packages, which resolves tosrc
, for example the import from@ckeditor/ckeditor5-utils
here, and there are many many other examples. So it's simply not safe to consume files fromdist/
folders because they might pull in files fromsrc/
folders that conflict with the correspondingdist/
file imported elsewhere in the module graph.❓ Possible solution
The most straightforward solution would probably be to change the
@ckeditor/ckeditor5-*
packages'main
andtypes
entries inpackage.json
to point todist
rather thansrc
, but this would be a change to the module layout that might raise compatibility issues.The other solution would be to ensure that modules in
dist/
always import from@ckeditor/ckeditor5-*/dist/*
rather than from the@ckeditor/ckeditor5-*
module roots.📃 Other notes
This makes importing from the
ckeditor5
module root, as well as consuming modules anywhere indist/
, un-tenable for my application at the moment. A workaround is to import fromckeditor5/src/index.js
rather thanckeditor5
, so I'm only consuming fromsrc/
, but based on the release notes, my impression is that CKEditor is trying to move consumers fromsrc/
todist/
. Unfortunately, that's not possible for me right now.If you'd like to see this fixed sooner, add a 👍 reaction to this post.
The text was updated successfully, but these errors were encountered: