two problems on implementing react without create-react-app?











up vote
0
down vote

favorite












I am creating a simple react app to practice creating stuffs without dependencies provided by create-react-app (webpack - babel ....)



I am faced with two problems



this is the code:



HTML



 <html>
<head><head>
<body>
<div id="App"> </div>
<script type="module" src="script.js" ></script>
<script crossorigin src="https://unpkg.com/react@16/umd/react.production.min.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script>
</body>
</html>


JS



window.onload = () => {
class App extends React.Component {
render() {
return(
<div className="App">
<p>any paragraph</p>
</div>
)
}
}

ReactDom.render(App, document.getElementById('App'))
}


The first problem is:



Nothing is happening when adding the type attribute to the script tag and set its value to "module", nothing works at all, as if js engine could not access the script!!



The second problem:



After removing type="module", it works but with a console error Uncaught SyntaxError: Unexpected token <



So why these two problems happens and how to solve them??










share|improve this question




















  • 2




    You need to transpile your JSX.
    – SLaks
    Nov 11 at 15:27






  • 2




    ^^ (or not use JSX, but...JSX is really handy)
    – T.J. Crowder
    Nov 11 at 15:28










  • ok i got that, what about the first problem
    – Saher Elgendy
    Nov 11 at 15:28










  • Since you have no module syntax (import/export) in your JS, why would you expect including it as a module to be useful?
    – MTCoster
    Nov 11 at 15:41










  • @MTCoster i used them but nothing worked, so why i am ask the question!!
    – Saher Elgendy
    Nov 11 at 15:47















up vote
0
down vote

favorite












I am creating a simple react app to practice creating stuffs without dependencies provided by create-react-app (webpack - babel ....)



I am faced with two problems



this is the code:



HTML



 <html>
<head><head>
<body>
<div id="App"> </div>
<script type="module" src="script.js" ></script>
<script crossorigin src="https://unpkg.com/react@16/umd/react.production.min.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script>
</body>
</html>


JS



window.onload = () => {
class App extends React.Component {
render() {
return(
<div className="App">
<p>any paragraph</p>
</div>
)
}
}

ReactDom.render(App, document.getElementById('App'))
}


The first problem is:



Nothing is happening when adding the type attribute to the script tag and set its value to "module", nothing works at all, as if js engine could not access the script!!



The second problem:



After removing type="module", it works but with a console error Uncaught SyntaxError: Unexpected token <



So why these two problems happens and how to solve them??










share|improve this question




















  • 2




    You need to transpile your JSX.
    – SLaks
    Nov 11 at 15:27






  • 2




    ^^ (or not use JSX, but...JSX is really handy)
    – T.J. Crowder
    Nov 11 at 15:28










  • ok i got that, what about the first problem
    – Saher Elgendy
    Nov 11 at 15:28










  • Since you have no module syntax (import/export) in your JS, why would you expect including it as a module to be useful?
    – MTCoster
    Nov 11 at 15:41










  • @MTCoster i used them but nothing worked, so why i am ask the question!!
    – Saher Elgendy
    Nov 11 at 15:47













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am creating a simple react app to practice creating stuffs without dependencies provided by create-react-app (webpack - babel ....)



I am faced with two problems



this is the code:



HTML



 <html>
<head><head>
<body>
<div id="App"> </div>
<script type="module" src="script.js" ></script>
<script crossorigin src="https://unpkg.com/react@16/umd/react.production.min.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script>
</body>
</html>


JS



window.onload = () => {
class App extends React.Component {
render() {
return(
<div className="App">
<p>any paragraph</p>
</div>
)
}
}

ReactDom.render(App, document.getElementById('App'))
}


The first problem is:



Nothing is happening when adding the type attribute to the script tag and set its value to "module", nothing works at all, as if js engine could not access the script!!



The second problem:



After removing type="module", it works but with a console error Uncaught SyntaxError: Unexpected token <



So why these two problems happens and how to solve them??










share|improve this question















I am creating a simple react app to practice creating stuffs without dependencies provided by create-react-app (webpack - babel ....)



I am faced with two problems



this is the code:



HTML



 <html>
<head><head>
<body>
<div id="App"> </div>
<script type="module" src="script.js" ></script>
<script crossorigin src="https://unpkg.com/react@16/umd/react.production.min.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script>
</body>
</html>


JS



window.onload = () => {
class App extends React.Component {
render() {
return(
<div className="App">
<p>any paragraph</p>
</div>
)
}
}

ReactDom.render(App, document.getElementById('App'))
}


The first problem is:



Nothing is happening when adding the type attribute to the script tag and set its value to "module", nothing works at all, as if js engine could not access the script!!



The second problem:



After removing type="module", it works but with a console error Uncaught SyntaxError: Unexpected token <



So why these two problems happens and how to solve them??







javascript reactjs






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 at 16:30

























asked Nov 11 at 15:26









Saher Elgendy

476




476








  • 2




    You need to transpile your JSX.
    – SLaks
    Nov 11 at 15:27






  • 2




    ^^ (or not use JSX, but...JSX is really handy)
    – T.J. Crowder
    Nov 11 at 15:28










  • ok i got that, what about the first problem
    – Saher Elgendy
    Nov 11 at 15:28










  • Since you have no module syntax (import/export) in your JS, why would you expect including it as a module to be useful?
    – MTCoster
    Nov 11 at 15:41










  • @MTCoster i used them but nothing worked, so why i am ask the question!!
    – Saher Elgendy
    Nov 11 at 15:47














  • 2




    You need to transpile your JSX.
    – SLaks
    Nov 11 at 15:27






  • 2




    ^^ (or not use JSX, but...JSX is really handy)
    – T.J. Crowder
    Nov 11 at 15:28










  • ok i got that, what about the first problem
    – Saher Elgendy
    Nov 11 at 15:28










  • Since you have no module syntax (import/export) in your JS, why would you expect including it as a module to be useful?
    – MTCoster
    Nov 11 at 15:41










  • @MTCoster i used them but nothing worked, so why i am ask the question!!
    – Saher Elgendy
    Nov 11 at 15:47








2




2




You need to transpile your JSX.
– SLaks
Nov 11 at 15:27




You need to transpile your JSX.
– SLaks
Nov 11 at 15:27




2




2




^^ (or not use JSX, but...JSX is really handy)
– T.J. Crowder
Nov 11 at 15:28




^^ (or not use JSX, but...JSX is really handy)
– T.J. Crowder
Nov 11 at 15:28












ok i got that, what about the first problem
– Saher Elgendy
Nov 11 at 15:28




ok i got that, what about the first problem
– Saher Elgendy
Nov 11 at 15:28












Since you have no module syntax (import/export) in your JS, why would you expect including it as a module to be useful?
– MTCoster
Nov 11 at 15:41




Since you have no module syntax (import/export) in your JS, why would you expect including it as a module to be useful?
– MTCoster
Nov 11 at 15:41












@MTCoster i used them but nothing worked, so why i am ask the question!!
– Saher Elgendy
Nov 11 at 15:47




@MTCoster i used them but nothing worked, so why i am ask the question!!
– Saher Elgendy
Nov 11 at 15:47












1 Answer
1






active

oldest

votes

















up vote
0
down vote













Try loading script.js last. That is, after react-dom is loaded.






share|improve this answer





















  • did not work too!!
    – Saher Elgendy
    Nov 12 at 15:56










  • You have incorrect html tag in your html code, correct that so it starts with <.
    – Rico Chen
    Nov 12 at 16:10










  • thank you but this was not the problem, it was just a problem of copy and paste, still good catch!!
    – Saher Elgendy
    Nov 12 at 16:31








  • 1




    Looks like you are trying to use JSX directly in a browser. You will need to include babel for that: add this line before script.js: <script crossorigin src="unpkg.com/babel-standalone@6.15.0/babel.min.js"></…>. Also you will need to change the type to 'text/babel' for script.js. Lastly, ReactDom.render(App, document.getElementById('App')) should be corrected to ReactDOM.render(<App />, document.getElementById('App'))
    – Rico Chen
    Nov 12 at 17:02










  • <script src="script.js" type="text/babel"></script> nothing worked at all, it was like adding the type="module"
    – Saher Elgendy
    Nov 12 at 17:42













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53250204%2ftwo-problems-on-implementing-react-without-create-react-app%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













Try loading script.js last. That is, after react-dom is loaded.






share|improve this answer





















  • did not work too!!
    – Saher Elgendy
    Nov 12 at 15:56










  • You have incorrect html tag in your html code, correct that so it starts with <.
    – Rico Chen
    Nov 12 at 16:10










  • thank you but this was not the problem, it was just a problem of copy and paste, still good catch!!
    – Saher Elgendy
    Nov 12 at 16:31








  • 1




    Looks like you are trying to use JSX directly in a browser. You will need to include babel for that: add this line before script.js: <script crossorigin src="unpkg.com/babel-standalone@6.15.0/babel.min.js"></…>. Also you will need to change the type to 'text/babel' for script.js. Lastly, ReactDom.render(App, document.getElementById('App')) should be corrected to ReactDOM.render(<App />, document.getElementById('App'))
    – Rico Chen
    Nov 12 at 17:02










  • <script src="script.js" type="text/babel"></script> nothing worked at all, it was like adding the type="module"
    – Saher Elgendy
    Nov 12 at 17:42

















up vote
0
down vote













Try loading script.js last. That is, after react-dom is loaded.






share|improve this answer





















  • did not work too!!
    – Saher Elgendy
    Nov 12 at 15:56










  • You have incorrect html tag in your html code, correct that so it starts with <.
    – Rico Chen
    Nov 12 at 16:10










  • thank you but this was not the problem, it was just a problem of copy and paste, still good catch!!
    – Saher Elgendy
    Nov 12 at 16:31








  • 1




    Looks like you are trying to use JSX directly in a browser. You will need to include babel for that: add this line before script.js: <script crossorigin src="unpkg.com/babel-standalone@6.15.0/babel.min.js"></…>. Also you will need to change the type to 'text/babel' for script.js. Lastly, ReactDom.render(App, document.getElementById('App')) should be corrected to ReactDOM.render(<App />, document.getElementById('App'))
    – Rico Chen
    Nov 12 at 17:02










  • <script src="script.js" type="text/babel"></script> nothing worked at all, it was like adding the type="module"
    – Saher Elgendy
    Nov 12 at 17:42















up vote
0
down vote










up vote
0
down vote









Try loading script.js last. That is, after react-dom is loaded.






share|improve this answer












Try loading script.js last. That is, after react-dom is loaded.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 11 at 19:44









Rico Chen

67348




67348












  • did not work too!!
    – Saher Elgendy
    Nov 12 at 15:56










  • You have incorrect html tag in your html code, correct that so it starts with <.
    – Rico Chen
    Nov 12 at 16:10










  • thank you but this was not the problem, it was just a problem of copy and paste, still good catch!!
    – Saher Elgendy
    Nov 12 at 16:31








  • 1




    Looks like you are trying to use JSX directly in a browser. You will need to include babel for that: add this line before script.js: <script crossorigin src="unpkg.com/babel-standalone@6.15.0/babel.min.js"></…>. Also you will need to change the type to 'text/babel' for script.js. Lastly, ReactDom.render(App, document.getElementById('App')) should be corrected to ReactDOM.render(<App />, document.getElementById('App'))
    – Rico Chen
    Nov 12 at 17:02










  • <script src="script.js" type="text/babel"></script> nothing worked at all, it was like adding the type="module"
    – Saher Elgendy
    Nov 12 at 17:42




















  • did not work too!!
    – Saher Elgendy
    Nov 12 at 15:56










  • You have incorrect html tag in your html code, correct that so it starts with <.
    – Rico Chen
    Nov 12 at 16:10










  • thank you but this was not the problem, it was just a problem of copy and paste, still good catch!!
    – Saher Elgendy
    Nov 12 at 16:31








  • 1




    Looks like you are trying to use JSX directly in a browser. You will need to include babel for that: add this line before script.js: <script crossorigin src="unpkg.com/babel-standalone@6.15.0/babel.min.js"></…>. Also you will need to change the type to 'text/babel' for script.js. Lastly, ReactDom.render(App, document.getElementById('App')) should be corrected to ReactDOM.render(<App />, document.getElementById('App'))
    – Rico Chen
    Nov 12 at 17:02










  • <script src="script.js" type="text/babel"></script> nothing worked at all, it was like adding the type="module"
    – Saher Elgendy
    Nov 12 at 17:42


















did not work too!!
– Saher Elgendy
Nov 12 at 15:56




did not work too!!
– Saher Elgendy
Nov 12 at 15:56












You have incorrect html tag in your html code, correct that so it starts with <.
– Rico Chen
Nov 12 at 16:10




You have incorrect html tag in your html code, correct that so it starts with <.
– Rico Chen
Nov 12 at 16:10












thank you but this was not the problem, it was just a problem of copy and paste, still good catch!!
– Saher Elgendy
Nov 12 at 16:31






thank you but this was not the problem, it was just a problem of copy and paste, still good catch!!
– Saher Elgendy
Nov 12 at 16:31






1




1




Looks like you are trying to use JSX directly in a browser. You will need to include babel for that: add this line before script.js: <script crossorigin src="unpkg.com/babel-standalone@6.15.0/babel.min.js"></…>. Also you will need to change the type to 'text/babel' for script.js. Lastly, ReactDom.render(App, document.getElementById('App')) should be corrected to ReactDOM.render(<App />, document.getElementById('App'))
– Rico Chen
Nov 12 at 17:02




Looks like you are trying to use JSX directly in a browser. You will need to include babel for that: add this line before script.js: <script crossorigin src="unpkg.com/babel-standalone@6.15.0/babel.min.js"></…>. Also you will need to change the type to 'text/babel' for script.js. Lastly, ReactDom.render(App, document.getElementById('App')) should be corrected to ReactDOM.render(<App />, document.getElementById('App'))
– Rico Chen
Nov 12 at 17:02












<script src="script.js" type="text/babel"></script> nothing worked at all, it was like adding the type="module"
– Saher Elgendy
Nov 12 at 17:42






<script src="script.js" type="text/babel"></script> nothing worked at all, it was like adding the type="module"
– Saher Elgendy
Nov 12 at 17:42




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53250204%2ftwo-problems-on-implementing-react-without-create-react-app%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python