Dependency Not found even defined in package.json and node_modules Dependency Not found even defined in package.json and node_modules vue.js vue.js

Dependency Not found even defined in package.json and node_modules


I took this debugging opportunity to learn more about npm and webpack.

It looks like the creators of photo-sphere-viewer did not specify where their "main" file was, the file that gets returned when you import or require. I think by default npm looks for index.js at the project root. But a lot of times, package creators put their distribution files under a dist or lib directory. The photo-sphere people did this, but did not specify the location in their package.json. The solution is to add

"main":"./dist/photo-sphere-viewer.min.js"

to the photo-sphere-viewer package.json file. Make sure to add a trailing comma if you're not putting it at the very end. Also i would recommend filing an issue on their Github, this seems like a bug..

Alternatively, you can also do

import PhotoSphereViewer from 'photo-sphere-viewer/dist/photo-sphere-viewer.min.js';