FredKSchott / snowpack

ESM-powered frontend build tool. Instant, lightweight, unbundled development. ✌️
https://www.snowpack.dev
MIT License
19.48k stars 922 forks source link

🐛 BUG: #3867

Open Bassadin opened 2 years ago

Bassadin commented 2 years ago

Quick checklist

What package manager are you using?

npm

What operating system are you using?

Windows

Describe the bug

I'm trying to build an application with Three.js, importing a class from their examples folder. Although they have that exported in their package.json, I get an eror as decribed on the snowpack website that it isn't exported: Package "three" exists but package.json "exports" does not include entry for "./examples/jsm/webxr/ARButton.js". .

Steps to reproduce

  1. Feel free to clone my code
  2. npm install
  3. npm run build

Link to minimal reproducible example (optional)

https://github.com/Bassadin/Three.LS

marcofugaro commented 2 years ago

I'll leave more info.

Three.js is using a valid node exports field, according to the node.js docs:

  "exports": {
    ".": {
      "import": "./build/three.module.js",
      "require": "./build/three.cjs"
    },
    "./examples/fonts/*": "./examples/fonts/*",
    "./examples/jsm/*": "./examples/jsm/*",
    "./src/*": "./src/*"
  },

in plain node.js, this import works correctly:

import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';

while on snowpack, the error reported above occurs.

jhsul commented 2 years ago

I am also encountering this issue

sagrimson commented 2 years ago

I'm having the same issue Package "three" exists but package.json "exports" does not include entry for "./examples/jsm/loaders/GLTFLoader".

jhsul commented 2 years ago

For a temporary fix, you can go into your local node_modules/three/package.json and add "./examples/jsm/loaders/*": "./examples/jsm/loaders/*" to the exports section. That's what I've been doing

sagrimson commented 2 years ago

Thanks @jhsul that worked for me! I also had to add the '.js' extension to my import: import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';