• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Why home is not defined?

Resolved: Why home is not defined?

0
By Isaac Tonny on 16/03/2023 Issue
Share
Facebook Twitter LinkedIn

In this post, we will see how to resolve Why home is not defined?

Question:

I am not sure why home is not defined when i do this in app.js? I tried to reference home.js with app.js by adding code
into app.js but then i got an error that said “Cannot use import statement outside a module”
Is that reference enough and should i focus my self to solve the second one error?
Index.html
home.js
app.js
Suggestion why home is not defined?

Best Answer:

Please check the MDN Docs about import
From Cannot use import statement outside a module in JavaScript

In JavaScript, a module is a code executed in its own scope, separate from the global scope. Import statements can only be used within a module and not in the global scope.


Fixing it for HTML


To fix the problem for HTML scripts, you need to set the element’s type attribute to specify the type of script included in the element.
If the type attribute is set to “module”, the browser will know that the script is a JavaScript module and will execute it as such.
This will allow you to use import statements within the script.
Here is an example:

If you have better answer, please add a comment about this, thank you!

Source: Stackoverflow.com

javascript vue.js
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Kivy widget hierarchy not behaving as expected

24/03/2023

Resolved: Pandas Groupby Get Values from Previous Group

24/03/2023

Resolved: Can’t access static methods from outside until JavaScript’s static block is over?

24/03/2023

Comments are closed.

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.