Why does the Relative Reference not work?

Viewed 45

I used this line of code in my HTML file (in VSCode)

[<script type="module" src="./classDef.js"></script>
<script type="module" src="./scripts.js"></script>][1]

but faced this error massage in Chrome Console:

Uncaught TypeError: Failed to resolve module specifier "classDef.js". Relative references must start with either "/", "./", or "../".

what is the problem or where I made a mistake? Thank you in advance


I tested and notice error is shown when I start to insert this code in js file:

import Book from '27classdef.js'

const iceAndFire = new Book(
    "a261",
    "Ice and Fire",
    "George R.R. Martin",
    "Fiction",
    352,
);

console.log(iceAndFire);
1 Answers

Just use the file name directly as:

[<script type="module" src="classDef.js"></script>
<script type="module" src="scripts.js"></script>][1]

Instead of src="./classDef.js" or src="./scripts.js"

Related