The following js code block in the example-report.md of the default example code of an observable project returns error, when three is already installed via npm install three for this project.
May I ask if I missed something important here?
Code:
import * as three from "three";
Error:
TypeError: Failed to resolve module specifier 'three'
```js echo
import * as THREE from "npm:three";
```
```js echo
const height = 300;
const camera = new THREE.PerspectiveCamera(70, width / height, 0.01, 10);
const scene = new THREE.Scene();
const geometry = new THREE.BoxGeometry(0.2, 0.2, 0.2);
const material = new THREE.MeshNormalMaterial();
const mesh = new THREE.Mesh(geometry, material);
const renderer = new THREE.WebGLRenderer({antialias: true});
camera.position.z = 1;
scene.add(mesh);
const animation = (time) => {
mesh.rotation.x = time / 2000;
mesh.rotation.y = time / 1000;
renderer.render(scene, camera);
};
renderer.setSize(width, height);
renderer.setAnimationLoop(animation);
display(renderer.domElement);
```
An alternative is to do npm install three (as you originally mentioned), and import from node_modules with import * as THREE from "three"; this also works for me under Framework ^1.6 (note that this is the version that was released yesterday, so maybe you just need to upgrade).
I figured out the source of the problem: The Great Firewall of China. (Iām in China now. No need for more explanation, right?..), or as I suspect.
Once I switch to using roaming data of a non-China mobile number to bypass the Great Firewall and connect to internet, the issue is gone.
The import * as THREE from "npm:three" solution still works even if I switch back to using local internet connection in China within the Great Firewall.
However, I still canāt get import * as THREE from "three" to work, with three@0.163.0 installed via npm, even if I use mobile roaming data for internet connection.
The message remains as TypeError: Failed to resolve module specifier 'three', which is strange because three.js is installed locally now.