question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Syntax Highlighter should import react-syntax-highlighter from CommonJS dist instead of ESModules

See original GitHub issue

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

({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import jsx from "refractor/lang/jsx.js";
                                                                                             ^^^^^^

    SyntaxError: Cannot use import statement outside a module

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:

var _jsx = _interopRequireDefault(require("react-syntax-highlighter/dist/esm/languages/prism/jsx"));

var _bash = _interopRequireDefault(require("react-syntax-highlighter/dist/esm/languages/prism/bash"));

var _css = _interopRequireDefault(require("react-syntax-highlighter/dist/esm/languages/prism/css"));

var _markup = _interopRequireDefault(require("react-syntax-highlighter/dist/esm/languages/prism/markup"));

var _tsx = _interopRequireDefault(require("react-syntax-highlighter/dist/esm/languages/prism/tsx"));

var _typescript = _interopRequireDefault(require("react-syntax-highlighter/dist/esm/languages/prism/typescript"));

fixed imports:

var _jsx = _interopRequireDefault(require("react-syntax-highlighter/dist/cjs/languages/prism/jsx"));

var _bash = _interopRequireDefault(require("react-syntax-highlighter/dist/cjs/languages/prism/bash"));

var _css = _interopRequireDefault(require("react-syntax-highlighter/dist/cjs/languages/prism/css"));

var _markup = _interopRequireDefault(require("react-syntax-highlighter/dist/cjs/languages/prism/markup"));

var _tsx = _interopRequireDefault(require("react-syntax-highlighter/dist/cjs/languages/prism/tsx"));

var _typescript = _interopRequireDefault(require("react-syntax-highlighter/dist/cjs/languages/prism/typescript"));

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

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:7
  • Comments:27 (15 by maintainers)

github_iconTop GitHub Comments

5reactions
Hypnosphicommented, Jan 1, 2020

Changing imports to cjs makes sense to me, please open a PR

@Rikpat as a temporary workaround, you can try adding following field to your jest.config.js:

transformIgnorePatterns: ['node_modules/(?!react-syntax-highlighter)']
4reactions
shilmancommented, Feb 7, 2020

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 @next NPM tag.

Closing this issue. Please re-open if you think there’s still more to do.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Syntax Highlighter - GitHub Pages
You can require PrismLight from react-syntax-highlighter to use the prism light build instead of the standard light build. import { PrismLight as ...
Read more >
shadow-cljs 2021-04-10 - Slack Archive
The import that fails is [react-syntax-highlighter :refer [Prism]] , the error is, the line that fails in the generated code is Object.
Read more >
cannot access 'user' before initialization - You.com
No need to import User model, try using following code. user: { type: mongoose. ... import { dark } from 'react-syntax-highlighter/dist/esm/styles/prism';.
Read more >
react-syntax-highlighter | Yarn - Package Manager
syntax highlighting component for react with prismjs or highlightjs ast using inline styles ... For React Native you can use react-native-syntax-highlighter ...
Read more >
Files changed (30) - Renovate Bot Package Diff
+ * If you do this, there's several things you should keep in mind: ... node_modules/@types/react-syntax-highlighter/index.d.ts","../../.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found