'Error resolving module specifier “three”. I am using npm to install three.js

I am using npm to install three.js according to official website of three and this is my project:

-> node_modules/three/
-> package-lock.json
-> package.json
-> index.html
-> index.js

my script tag to load script:

<script src="index.js" type="module" defer></script>

my script:

import * as THREE from 'three'
console.log(THREE)

then i open it through local server but at the end i get this error on my browser (firefox dev. edition):

Uncaught TypeError: Error resolving module specifier “three”. Relative module specifiers must start with “./”, “../” or “/”.

seriously I looked everywhere for a solution but can't find.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source