Search code examples
javascriptimporterrornetlifyparceljs

How to import javascript libraries using Parcel/Netlify?


I'm building a vanilla js app and using CDN's works fine, but If I install an app like typed.js with npm, and then import it as import typed from 'typed.js' it works as it should on a local dev server.

However, once I push it and it's built on Netlify I get a console error stating: failed to resolve module specifier "typed.js". relative references must start with either "/", "./", or "../".

I have tried changing the import in every way I can think of like 'typed' , '/typed' , '/typed.js' , 'typed.js' , 'typed.js/lib/typed.js' , typed.js/src/typed.js' etc and using require instead of import.


Solution

  • It ended up being a very easy fix with Netlify, I needed to change the publish directory to "dist" within the build settings.