Skip to content

README Wrong: When used as an npm module, ThreeJS is a required peer dependency but not marked as so in the readme #4197

@johnnyshankman

Description

@johnnyshankman

Description

In the readme it does not clearly state that you need to install ThreeJS as a peer dependency of this package when using NPM. I find that if I do not also install a version of ThreeJS in my project, the NPM module cannot properly build. This is not the case with the unpkg version being served via <script> tag on the page, to be clear.

https://github.com/google/model-viewer/blob/master/packages/model-viewer/package.json#L78-L80

See: https://github.com/google/model-viewer/tree/master/packages/model-viewer

Live Demo

Just follow the README for NPM usage.

yarn install @google/model-viewer

Now in your app

import '@google/model-viewer';

In your compiler you will find something along the lines of:

These dependencies were not found:

* three in ./node_modules/@google/model-viewer/lib/model-viewer.js, ./node_modules/@google/model-viewer/lib/features/animation.js and 3 others
* three/examples/jsm/exporters/GLTFExporter.js in ./node_modules/@google/model-viewer/lib/features/scene-graph.js
* three/examples/jsm/exporters/USDZExporter.js in ./node_modules/@google/model-viewer/lib/features/ar.js
* three/examples/jsm/loaders/DRACOLoader.js in ./node_modules/@google/model-viewer/lib/three-components/CachingGLTFLoader.js
* three/examples/jsm/loaders/GLTFLoader.js in ./node_modules/@google/model-viewer/lib/three-components/CachingGLTFLoader.js
* three/examples/jsm/loaders/KTX2Loader.js in ./node_modules/@google/model-viewer/lib/three-components/CachingGLTFLoader.js
* three/examples/jsm/loaders/RGBELoader.js in ./node_modules/@google/model-viewer/lib/three-components/TextureUtils.js
* three/examples/jsm/renderers/CSS2DRenderer.js in ./node_modules/@google/model-viewer/lib/three-components/ModelScene.js
* three/examples/jsm/shaders/HorizontalBlurShader.js in ./node_modules/@google/model-viewer/lib/three-components/Shadow.js
* three/examples/jsm/shaders/VerticalBlurShader.js in ./node_modules/@google/model-viewer/lib/three-components/Shadow.js
* three/examples/jsm/utils/SceneUtils.js in ./node_modules/@google/model-viewer/lib/three-components/ModelScene.js
* three/examples/jsm/utils/SkeletonUtils.js in ./node_modules/@google/model-viewer/lib/three-components/GLTFInstance.js
* three/examples/jsm/webxr/XREstimatedLight.js in ./node_modules/@google/model-viewer/lib/three-components/ARRenderer.js
* three/src/math/MathUtils.js in ./node_modules/@google/model-viewer/lib/three-components/Shadow.js

To install them, you can run: npm install --save three three/examples/jsm/exporters/GLTFExporter.js three/examples/jsm/exporters/USDZExporter.js three/examples/jsm/loaders/DRACOLoader.js three/examples/jsm/loaders/GLTFLoader.js three/examples/jsm/loaders/KTX2Loader.js three/examples/jsm/loaders/RGBELoader.js three/examples/jsm/renderers/CSS2DRenderer.js three/examples/jsm/shaders/HorizontalBlurShader.js three/examples/jsm/shaders/VerticalBlurShader.js three/examples/jsm/utils/SceneUtils.js three/examples/jsm/utils/SkeletonUtils.js three/examples/jsm/webxr/XREstimatedLight.js three/src/math/MathUtils.js

The way to fix it is to add this is to add the missing peer dependency:

yarn add @google/model-viewer

And ensure the version is at least 0.151.2

This is nowhere mentioned in the README which caused me a bunch of frustration and time loss during my day. I didn't solve this until another engineer thought to check your package.json for peer deps.

Version

  • model-viewer: v3.0.2
"@google/model-viewer": "3.0.2",

Browser Affected

N/A

OS

N/A

AR

N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions