-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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
Syntax Highlighter should import react-syntax-highlighter from CommonJS dist instead of ESModules #9279
Comments
@Hypnosphi mind taking a look? |
Changing imports to @Rikpat as a temporary workaround, you can try adding following field to your
|
I've made the changes, I only need to verify whether I should keep the requires in as consts like this const jsx = require('react-syntax-highlighter/dist/cjs/languages/prism/jsx').default;
const bash = require('react-syntax-highlighter/dist/cjs/languages/prism/bash').default;
const css = require('react-syntax-highlighter/dist/cjs/languages/prism/css').default;
const html = require('react-syntax-highlighter/dist/cjs/languages/prism/markup').default;
const tsx = require('react-syntax-highlighter/dist/cjs/languages/prism/tsx').default;
const typescript = require('react-syntax-highlighter/dist/cjs/languages/prism/typescript').default;
ReactSyntaxHighlighter.registerLanguage('jsx', jsx);
ReactSyntaxHighlighter.registerLanguage('bash', bash);
ReactSyntaxHighlighter.registerLanguage('css', css);
ReactSyntaxHighlighter.registerLanguage('html', html);
ReactSyntaxHighlighter.registerLanguage('tsx', tsx);
ReactSyntaxHighlighter.registerLanguage('typescript', typescript); or if I can inline them since they are only used in single function like this ReactSyntaxHighlighter.registerLanguage(
'jsx',
require('react-syntax-highlighter/dist/cjs/languages/prism/jsx').default
);
ReactSyntaxHighlighter.registerLanguage(
'bash',
require('react-syntax-highlighter/dist/cjs/languages/prism/bash').default
);
ReactSyntaxHighlighter.registerLanguage(
'css',
require('react-syntax-highlighter/dist/cjs/languages/prism/css').default
);
ReactSyntaxHighlighter.registerLanguage(
'html',
require('react-syntax-highlighter/dist/cjs/languages/prism/markup').default
);
ReactSyntaxHighlighter.registerLanguage(
'tsx',
require('react-syntax-highlighter/dist/cjs/languages/prism/tsx').default
);
ReactSyntaxHighlighter.registerLanguage(
'typescript',
require('react-syntax-highlighter/dist/cjs/languages/prism/typescript').default
); |
@Rikpat please keep the import jsx from 'react-syntax-highlighter/dist/cjs/languages/prism/jsx';
import bash from 'react-syntax-highlighter/dist/cjs/languages/prism/bash';
import css from 'react-syntax-highlighter/dist/cjs/languages/prism/css';
import html from 'react-syntax-highlighter/dist/cjs/languages/prism/markup';
import tsx from 'react-syntax-highlighter/dist/cjs/languages/prism/tsx';
import typescript from 'react-syntax-highlighter/dist/cjs/languages/prism/typescript'; It's OK to |
@Hypnosphi Sorry I didn't notice your reply before I finished the changes Otherwise we would need to create a declaration for all of the imported modules |
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks! |
@Rikpat @Hypnosphi Hi! any updates on the PR? |
@alexandrzavalii #9292 (comment)
No one did it yet AFAIK, so you can |
@Hypnosphi, the workaround you suggested doesn't seem to work for me (looks like react-syntax-highlighter is required for some reason). Is there some way to modify the path from ESM to CJS using the config? |
There isn't AFAIK |
` ({"Object.":function(module,exports,require,__dirname,__filename,global,jest){import jsx from "refractor/lang/jsx.js"; ^^^ I am also receiving this. Any update on a fix? |
Also receiving the same error as @weber93 using storybook/storyshots with jest (default nextjs config) |
@Hypnosphi |
Olé!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.0.0-alpha.7 containing PR #9780 that references this issue. Upgrade today to try it out! You can find this prerelease on the Closing this issue. Please re-open if you think there's still more to do. |
Gadzooks!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.0.0-alpha.9 containing PR #9795 that references this issue. Upgrade today to try it out! You can find this prerelease on the |
@shilman works for me! |
@alexandrzavalii thanks for the contribution!! you rock!!! 💯 |
Is this slated to be ported to 5.3? I'm running into this issue there. |
Nevermind! I see from the discussion that it is. Thanks! |
Crikey!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.0.0-alpha.24 containing PR #9292 that references this issue. Upgrade today to try it out! You can find this prerelease on the |
Has there been a non-prerelease version released that fixes this or is it still to come? |
Hi guys, I still get the error, even after updating to v6 everything storybook related:
Anything I might be missing?
|
@vasilevach Please remove this line:
|
@neil-morrison44 coming in the next couple days |
Jeepers creepers!! I just released https://github.com/storybookjs/storybook/releases/tag/v5.3.17 containing PR #9780 that references this issue. Upgrade today to try it out! |
I was still getting this on 6.0.0-beta.19 (and addon-info alpha.2):
In the end this was the transformIgnorePatterns I needed (adding both
|
Is your feature request related to a problem? Please describe.
I have a problem when using Storyshots (It may be a jest misconfiguration, since I'm not really proficient in that, but I've tried everything to fix it), that syntaxhighlighter imports react-syntax-highlighter from it's esm distribution which creates an error for me
Describe the solution you'd like
I would like to import react-syntax-highlighter from their cjs dist, since syntaxhighlighter component itself is written in commonjs. This fixed my issue locally.
Current imports:
fixed imports:
Describe alternatives you've considered
I've been trying to fix the jest config for 2 days now, if you can suggest me how to fix this without the need to change these imports, please do.
Are you able to assist bring the feature to reality?
yes, I can create a PR right away
The text was updated successfully, but these errors were encountered: