Import Assertions use “with” not “assert” anymore.

Chris Coyier Chris Coyier on

I was trying to play with CSS Module Scripts the other day, which are a way to import CSS as a constructable stylesheet using the ESModules syntax. They are Chrome-only so not really something we can generally use (unless you’re building an Electron app or something), but I really like the idea of being able to load a stylesheet for a web component in a separate file cleanly. Anyway, there is lots of information out there that shows and old syntax that doesn’t work anymore, and little information that the syntax has changed to use the with keyword.

// NOPE, old
import sheet from './styles.css' assert { type: 'css' };

// YEP, they changed it
import sheet from './styles.css' with { type: 'css' };Code language: JavaScript (javascript)

So they are called “import attributes” now also, best I can tell. I imagine it applies to the JSON version as well. Hope this saves someone some grief.

It's time to take your JavaScript to the next level

Frontend Masters logo

Frontend Masters is the best place on the web to really learn JavaScript. We have a complete learning path from the biggest and best teachers in JavaScript to help you make the most out of the web's biggest language.

7-Day Free Trial

Leave a Reply

Your email address will not be published. Required fields are marked *

Did you know?

Frontend Masters Donates to open source projects. $363,806 contributed to date.