I am trying to import a 3rd party javascript library into my LWC and everytime I try to push the code to my Scratch Org, I get the below error.
LWC1513: @salesforce/resourceUrl modules only support default imports.
The library consists to 2 files:
- A javascript file
- A CSS file
I have zipped these 2 files into one and uploaded them as a static resource. I use the below code in the js file of my LWC:
import { Library } from '@salesforce/resourceUrl/CustomLibrary';
The static resource has the name 'CustomLibrary' in my org. The push succeeds without this line of code though. I spent enough time to figure out what is going wrong but with little success.
I came across a similar link on Stack Overflow, but that didn't help me either.
Best Answer
Default imports dont use curly braces, therefore, your import would be as follows:
import Library from '@salesforce/resourceUrl/CustomLibrary';
this is standard across library imports from the static resource library.
for a more in depth explanation, you can refer to the Javascript Reference documentation
and the LWC Documentation on Accessing Static Resources