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

Update CKEditor 34 -> 35: SyntaxError: Identifier 'global' has already been declared #12971

Closed
alexander-schranz opened this issue Dec 5, 2022 · 11 comments · Fixed by #12972
Closed
Assignees
Labels
squad:core Issue to be handled by the Core team. type:bug This issue reports a buggy (incorrect) behavior.

Comments

@alexander-schranz
Copy link
Contributor

📝 Provide detailed reproduction steps (if any)

I run into the follwoing issue:

SyntaxError: Identifier 'global' has already been declared

When running our tests with Jest after updating CKEditor 34 -> 35.

  1. Run jest tests on Update CKEditor to version 35 sulu/sulu#6926

✔️ Expected result

What is the expected result of the above steps?

Tests should not fail.

❌ Actual result

What is the actual result of the above steps?

● Test suite failed to run

    /home/runner/work/sulu/sulu/node_modules/@ckeditor/ckeditor5-utils/src/dom/global.js:29
    let global;
        ^

    SyntaxError: Identifier 'global' has already been declared

      2 | import React from 'react';
      3 | import log from 'loglevel';
    > 4 | import AlignmentPlugin from '@ckeditor/ckeditor5-alignment/src/alignment';
        | ^

❓ Possible solution

If you have ideas, you can list them here. Otherwise, you can delete this section.

📃 Other details


If you'd like to see this fixed sooner, add a 👍 reaction to this post.

@alexander-schranz alexander-schranz added the type:bug This issue reports a buggy (incorrect) behavior. label Dec 5, 2022
@carlartz
Copy link

carlartz commented Dec 5, 2022

We are having the same issue when running our Jest Tests with CKEditor 35.

@alexander-schranz
Copy link
Contributor Author

@carlartz I tried do debug it more, it seems like Jest itself does not like the global name for variable I changed node_modules/@ckeditor/ckeditor5-utils/src/dom/global.js:

-let global;
+let globalVar;
// In some environments window and document API might not be available.
try {
-    global = { window, document };
+    globalVar = { window, document };
}
catch (e) {
    // It's not possible to mock a window object to simulate lack of a window object without writing extremely convoluted code.
    /* istanbul ignore next */
    // Let's cast it to not change module's API.
    // We only handle this so loading editor in environments without window and document doesn't fail.
    // For better DX we shouldn't introduce mixed types and require developers to check the type manually.
    // This module should not be used on purpose in any environment outside browser.
-    globalVar = { window: {}, document: {} };
+    globalVar = { window: {}, document: {} };
}
-export default global;
+export default globalVar;

Does this also fix it in your case?

@otto10
Copy link

otto10 commented Dec 5, 2022

Same Issue with Jest when upgrading to CKEditor 35. Keeping an eye here. Following the thread.

@alexander-schranz
Copy link
Contributor Author

@otto10 can you test if the rename would also fix it in your case?

@CKEditorBot CKEditorBot added the status:in-progress Set automatically when an issue lands in the "In progress" column. We are working on it. label Dec 5, 2022
@carlartz
Copy link

carlartz commented Dec 5, 2022

This should work, we renamed the variable locally and our tests ran successfully. Would this impact CKEditor running in our application?

@alexander-schranz
Copy link
Contributor Author

@carlartz Thx for testing. As let normally defines scoped variables this should have zero effect if we rename the variable in that file as it is private variable. Lets wait what the CKEditor core team says about the change :).

@Reinmar Reinmar added the squad:platform Issue to be handled by the Platform team. label Dec 12, 2022
@pomek pomek added squad:core Issue to be handled by the Core team. and removed squad:platform Issue to be handled by the Platform team. labels Dec 13, 2022
@alexander-schranz
Copy link
Contributor Author

@Reinmar @pomek Let me know if you need any more information and if I can do something to push this forward :)

@pomek
Copy link
Member

pomek commented Dec 21, 2022

cc: @arkflpc

@mremiszewski mremiszewski self-assigned this Dec 28, 2022
arkflpc added a commit that referenced this issue Dec 29, 2022
Internal (utils): Changes `global` variable name to avoid syntax error. Closes #12971.

Thanks to @alexander-schranz!
@CKEditorBot CKEditorBot removed the status:in-progress Set automatically when an issue lands in the "In progress" column. We are working on it. label Dec 29, 2022
@CKEditorBot CKEditorBot added this to the iteration 60 milestone Dec 29, 2022
@Reinmar
Copy link
Member

Reinmar commented Dec 30, 2022

Apologies to everyone – I forgot about this issue. Fortunately, @mremiszewski and @arkflpc corrected my mistake :) Sorry it took so long!

@Reinmar
Copy link
Member

Reinmar commented Dec 30, 2022

BTW, I wonder what's the root cause of this problem? Why does Jest have a problem with that variable? I'm a bit afraid that we fixed this particular issue but we'll hit the same problem elsewhere later on too.

@alexander-schranz
Copy link
Contributor Author

alexander-schranz commented Dec 30, 2022

@Reinmar jest defines a global const called global so you can not use let global somewhere. So it could maybe be catched with a eslint rule to avoid this variables named global.

Its something like this:

function jest(global) {
    // ckeditor
    let global = 2;
}

jest();

It is very similar to that you can not do let window = 'test'; inside a browser script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
squad:core Issue to be handled by the Core team. type:bug This issue reports a buggy (incorrect) behavior.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants