question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

docs(Installation): import OrbitControls from Skypack CDN is not working

See original GitHub issue

Describe the bug

Try using the OrbitControls from Skypack CDN according to the installation section but not working now.

Seems after #23255 merged, it also needs to use import maps before importing modules in examples.

And also I found the Skypack CDN will still try to export the default even though a js module has no default export.

After I tried, I solved these two problems with the following code:

<script type="importmap">
  {
    "imports": {
      "three": "https://cdn.skypack.dev/three"
    }
  }
</script>

<script type="module">

  // Find the latest version by visiting https://cdn.skypack.dev/three.

  import { OrbitControls } from 'https://unpkg.com/three/examples/jsm/controls/OrbitControls.js';

  const controls = new OrbitControls( camera, renderer.domElement );

</script>

I think the related docs can be updated to this, what do you think? But in my solution, I’m using two different CDNs. In case Skypack is currently unavailable, I wonder if we can switch all to unpkg (https://unpkg.com/three/build/three.module.js)?

To Reproduce

Steps to reproduce the behavior:

  1. Create a new pen from https://codepen.io
  2. Paste below code

Code

<script type="module">

  // Find the latest version by visiting https://cdn.skypack.dev/three.

  import { OrbitControls } from 'https://cdn.skypack.dev/three/examples/jsm/controls/OrbitControls.js';

  const controls = new OrbitControls( camera, renderer.domElement );

</script>

Expected behavior

Successful import.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
mrdoobcommented, Feb 4, 2022

Should we just change the links to use https://unpkg.com/ instead?

2reactions
marcofugarocommented, Feb 4, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught TypeError when accessing OrbitControls ... - GitHub
This appears to be a temporary problem with the Skypack CDN, and is reported on their status page here: https://status.skypack.dev/.
Read more >
npm:three-orbit-controls - Skypack.dev
Git clone, npm install and then run npm start to spin up a development server. Open localhost:9966 in your browser to see the...
Read more >
three.js / OrbitControls is not defined - Stack Overflow
You are mixing ES6 module with non-module code which is not valid. Do it like so: <script type="module"> import * as THREE from ......
Read more >
Installation – three.js docs
Addons do not need to be installed separately, but do need to be imported separately. If three.js was installed with npm, you can...
Read more >
THREE.js orbit controls - Anvil Works
And then amend the import statement to be what we want. <script type="module"> import {OrbitControls} from 'https://cdn.skypack.dev/@three-ts/ ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found