Question:

LWC1513: @salesforce/resourceUrl modules only support default imports

Ellie: 2 weeks ago

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:

  1. A javascript file
  2. 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.

Answer:
Aurora: 2 weeks ago

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 (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#Importing_defaults)

and the LWC Documentation on Accessing Static Resources (https://developer.salesforce.com/docs/component-library/documentation/lwc/lwc.create_resources)