K
K
kamelot432020-08-19 13:41:36
JavaScript
kamelot43, 2020-08-19 13:41:36

How to add a react component to an existing site?

I have prepared a react component and want to use it on an existing site. I'm using an example from the react spec. When trying to connect the component in the console, an error occurs:

Uncaught SyntaxError: Cannot use import statement outside a module

I tried using the type="module" attribute when including the script, but that didn't work either. How can I correctly add a react-component on the site? What could be the problem with connecting my component? Can I see working examples somewhere? Finished component . An example of its use on the site .

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Robur, 2020-08-19
@Robur

here they say that import cannot be used like this: https://github.com/babel/babel-standalone/issues/71
you need to build the webpack bundle normally.
as an option, you can try changing babel settings so that it generates not a commonjs module (this is the default babel-standalone setting) but es-module, then there is a chance that type="module" will work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question