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.

Runtime error (missing node module) when using ParcelJS

See original GitHub issue

My project uses Parcel as a build tool. I created a file index.tsx containing the following:

import React from "react";
import SyntaxHighlighter from 'react-syntax-highlighter';
const Component = () => {
  const codeString = '(num) => num + 1';
  return <SyntaxHighlighter language='javascript'>{codeString}</SyntaxHighlighter>;  
}

I am able to build this with Parcel (v1.12.3), but when I open the page in the browser, I get the following runtime error:

Uncaught (in promise) Error: Cannot find module ‘…/…/node_modules/refractor/lang/markup.js’ at newRequire (syntaxtest.f69400ca.js:37) at newRequire (core.c556c4e5.js:29) at newRequire (refractor.04149aff.js:29) at newRequire (core.c556c4e5.js:21) at localRequire (core.c556c4e5.js:53) at Object.parcelRequire…/…/node_modules/refractor/core.js.hastscript (core.js:23) at newRequire (core.c556c4e5.js:47) at newRequire (refractor.04149aff.js:29) at newRequire (syntaxtest.f69400ca.js:21) at localRequire (syntaxtest.f69400ca.js:53)

I tried to also install refractor, but that didn’t solve the issue. Does anybody have an idea what the problem might be?

Desktop (please complete the following information):

  • OS: macOS
  • Browser Chrome v73, Safari 12.1

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:6
  • Comments:7

github_iconTop GitHub Comments

4reactions
Multimocommented, Oct 8, 2019

Hey just for anyone else who happens to his this problem: @zamotany’s solution has worked for me but I had to use the common js dist instead as my node version had troubled with esm / import syntax.

import Prism from 'react-syntax-highlighter/dist/cjs/prism';
4reactions
zamotanycommented, Jul 9, 2019

I was having the same issue when importing prism:

import { Prism } from 'react-syntax-highlighter';

and I found that importing prism directly from dist/esm seems to do the trick:

import Prism from 'react-syntax-highlighter/dist/esm/prism';

For highlight.js this could work:

import Prism from 'react-syntax-highlighter/dist/esm/default-highlight';
Read more comments on GitHub >

github_iconTop Results From Across the Web

Runtime error (missing node module) when using ParcelJS
My project uses Parcel as a build tool. I created a file index.tsx containing the following: import React from "react"; ...
Read more >
Migration - Parcel
The first thing to note when upgrading from Parcel 1 to Parcel 2 is that the npm package name has changed from parcel-bundler...
Read more >
Dependency resolution - Parcel
Parcel implements an enhanced version of the Node module resolution algorithm. It is responsible for turning a dependency specifier into an absolute path ......
Read more >
Node Emulation - Parcel
Parcel includes several features that emulate the Node.js API. ... When running parcel build , NODE_ENV is set to production by default, otherwise...
Read more >
Diagnostics and Logging - Parcel
The ThrowableDiagnostic class in the @parcel/diagnostic package extends the JavaScript Error object with support for diagnostics. When throwing an error ...
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