Cannot import three

Following the installation guide on https://threejs.org/docs/#manual/en/introduction/Installation, I installed three via npm and wrote import * as THREE from ‘three’. But it didn’t work, the browser console gave an error message: “Failed to load module script: The server responded with a non-JavaScript MIME type of “text/html”. Strict MIME type checking is enforced for module scripts per HTML spec.”

How to import three properly?

If you’re using npm, you should combine it with either a bundler (ex. webpack) or a local webserver / CDN (that’ll serve module files.) Looking at the error you seem to be mixing several approaches from the guide, and instead of a javascript file a 404 error page is returned.

Take a look at the devtools Network tab, it may tell you exactly what is fetched when you try to import the three module.

1 Like