Unable to import javascript from npm package in Sage 9

I’ll chime in here too: perhaps it helps someone.

I found that when I had issues with certain imports, I was able to solve it by importing specific files (check node_modules which ones you want) such as with this scenario:

  1. Adding external library: in your theme root yarn add magnific-popup

  2. In your relevant stylesheet scss below @import "./autoload/**/*";:
    @import "~magnific-popup/dist/magnific-popup.css";

  3. In your relevant script file on top:
    import 'magnific-popup/dist/jquery.magnific-popup.js';