0

I have react app I created using create-react-app. I am tying to take user code and evaluate it to render it.

Here is what I have tried so far.

import React, { Component } from 'react';
import './App.css';
import { transform } from "@babel/standalone";

const code =  transform("<span>Hello world</span>", {
  presets: ["@babel/react", "@babel/env"],
}).code

class App extends Component {
  render() {
    return (
      <div className="App">
       <div>
         {eval(code)}
       </div>
      </div>
    );
  }
}

This code gives me the following error in my terminal.

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

I am on a mac if that matters.

4
  • as I mentioned, the goal is to take user entered code and render it, Commented Jan 10, 2019 at 16:44
  • Right, should have read it more carefully, sorry Commented Jan 10, 2019 at 16:48
  • have you tried increasing the memory available to nodejs? Commented Jan 10, 2019 at 16:51
  • Yes, just increased to 8gb, no luck Commented Jan 10, 2019 at 16:57

1 Answer 1

0

I got the same error with a large react project, to fix it I made my large imports more specific.

For example:
from -

import {SelectBox} from 'somelibrary-react';

to -

import SelectBox from 'somelibrary-react/select-box';

more explanation you can find here: bundle size

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.