0

I have a folder for test only that contain only 3 file

  • index.js
  • sample.js
  • index.html

Index.html

<!DOCTYPE html>
<html>

<head>

    <script src="index.js"></script>
    <title>Page Title</title>
</head>

<body>

    <h1>This is a Heading</h1>
    <p>This is a paragraph.</p>

</body>

</html>

index.js

import { data } from './sample';
console.log(data)
const newObj = Object.entries(sampleOb).filter((item, index) => index === 0)
console.log(Object.fromEntries(newObj) )

sample.js

export const data = {
    name:"abc",
    age:"19"
}

But problem is when i try to import data.js to index.js, it show this error enter image description here So how to fix this, thank you

2
  • Not a major issue in this case, but posting this for awareness of when to use images in questions: meta.stackoverflow.com/questions/285551/… Commented May 10, 2022 at 2:47
  • hint: script can have a module type Commented May 10, 2022 at 2:48

1 Answer 1

2

The issue is that index.js is declared as a script but not as one which is a module. You can learn more about declaring a script as a module from MDN.

Your code would be more correct as:

<script src="index.js" type="module"></script>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.