1

I'm using React 17.0.1 via CRA.

I have one module that I'm using called 'react-vimjs' that is causing this error. In node_modules/react-vimjs/src/main.tsx it uses the spread operator {...props} somewhere and this throws the error:

TypeError: React.__spread is not a function

However, when I use the spread operator in my OWN files (src/index.tsx), it works fine. But when I import that module & use it, it crashes. Why is this being interpreted differently? How do I fix this?

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import Vim, {FileUpload} from 'react-vimjs'
import reportWebVitals from './reportWebVitals';

class VimMarkdown extends React.Component<Props> {

  constructor(props: Props){
    super(props);
  }
  
  render = () => {
    const props = {
      memPath: './static/vim.js.mem',
    }
    return(
      <div className="vim">
        <Vim {...props} ref="vim"></Vim>
      </div>
    )
  }
}

interface Props{}

ReactDOM.render(
  <React.StrictMode>
  <VimMarkdown/>
  </React.StrictMode>,
  document.getElementById('root')
);
reportWebVitals();
Ali Esmailpor
  • 1,209
  • 3
  • 11
  • 22
Raven
  • 529
  • 7
  • 27
  • 3
    Please create a minimal reproduction case. It's unlikely we can solve this via a verbal description alone. – Jared Smith Jan 27 '21 at 02:53
  • I've updated the code. Not sure how much that will help since the error is being emitted from the external module. My spread operator works just fine. – Raven Jan 27 '21 at 02:57
  • Found a similar unanswered thread 2 years ago - https://stackoverflow.com/questions/51778230/react-project-spread-operator-in-node-module-unexpected-token – Raven Jan 27 '21 at 02:58
  • 1
    The last commit for that library was 5 years ago, I assume that's why it's not supported. – Phix Jan 27 '21 at 03:15
  • @Phix How is that a reason? The spread operator existed then and it exists now. The question is why is it being misunderstood in one place and not in another. – Raven Jan 27 '21 at 03:17
  • I'm still interested in instructions on how to fix this – Raven Jan 27 '21 at 03:37

0 Answers0