-1

This is my folder structure:

enter image description here

These are my files:

/* index.html */
<body>
  <h1>Modules</h1>
  <script type="module" src="./index.js"></script>
</body>

// index.js
import fruits from "./fruits";

console.log(fruits);

// fruits.js
const arr = ["Mango", "Appple", "Banana", "Guava"];

export default arr;

Everything looks fine to me, still I am getting the error: net::ERR_ABORTED 404 (Not Found).

2 Answers2

1

Browsers do not have Node.js style module resolution. You have to specify the exact URL to the module.

import fruits from "./fruits.js";

And remove this:

<script type="module" src="./fruits.js"></script>

… it doesn't do anything. It's only useful when you import it somewhere else.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
-1

Try import fruits from "./fruits.js";

Instead of import fruits from "./fruits";

Usman
  • 333
  • 3
  • 14