Home Sass Meta meta.get-module() Definition
Definition and Usage meta.get-module($name) returns the module value for a module you already loaded with @use. $name is the namespace —the last part of the URL, or the alias you chose with as.
Load it with @use "sass:meta". Requires Dart Sass 1.105+ .
Namespace, not URL. Pass "theme" for @use "theme", or "t" for @use "theme" as t. For built-ins, use the namespace such as "math", not "sass:math".
Not loading anything. meta.get-module() never loads a file. For that, use meta.load() .
Unknown namespace = error. If no module with that namespace exists in the current file, Sass stops with “There is no module with namespace…”.
Syntax
Syntax @use "sass:meta";
@use "theme";
@use "other" as o;
@use "sass:math";
meta.get-module($name); //=> module
$theme: meta.get-module("theme");
$other: meta.get-module("o");
$math: meta.get-module("math");
meta.module-variables($theme); // map of variables
meta.get-function("rem", $module: $theme);
// Module API — Dart Sass 1.105+ Pattern: @use a module → meta.get-module("namespace") → pass the value to other meta functions.
Code
SCSS Examples Examples target Dart Sass 1.105+ with @use "sass:meta". Helper files are shown above each main file. Open View Compiled CSS to see the result.
1. Namespace 2. Alias 3. Built-in module 4. Module members 5. Unknown name Example 1 — Turn a Namespace into a Module Fetch the module for @use "theme".
$primary: #036 !default;
$radius: 4px !default;
.theme {
color: $primary;
} @use "sass:meta";
@use "theme";
$module: meta.get-module("theme");
.info {
--type: #{meta.type-of($module)};
--inspect: #{meta.inspect($module)};
} .theme {
color: #036;
}
.info {
--type: module;
--inspect: get-module("theme");
} How It Works @use "theme" loads the file and creates the namespace theme.meta.get-module("theme") returns its module value.meta.type-of reports module..theme appears once because of @use, not because of get-module.Example 2 — Use the Alias, Not the URL With as t, the namespace is t.
$primary: #036 !default;
$radius: 4px !default;
.theme {
color: $primary;
} @use "sass:map";
@use "sass:meta";
@use "theme" as t;
$module: meta.get-module("t");
.card {
color: map.get(meta.module-variables($module), "primary");
} .theme {
color: #036;
}
.card {
color: #036;
} How It Works as t renames the namespace to t.meta.get-module("t") uses that alias.meta.module-variables reads the variable map from the module.map.get returns #036.Example 3 — Fetch a Built-In Module Built-ins are modules too—use their namespace.
@use "sass:map";
@use "sass:math";
@use "sass:meta";
$math: meta.get-module("math");
.constants {
--type: #{meta.type-of($math)};
--pi: #{map.get(meta.module-variables($math), "pi")};
} .constants {
--type: module;
--pi: 3.1415926536;
} How It Works @use "sass:math" creates the namespace math.meta.get-module("math") returns the built-in module.module-variables exposes constants like pi.See math constants .Example 4 — List Functions, Mixins, and Variables The same module value works with every module-* function.
@use "sass:math";
$primary: #036 !default;
@function rem($px) {
@return math.div($px, 16px) * 1rem;
}
@mixin stretch {
display: flex;
flex: 1;
} @use "sass:map";
@use "sass:meta";
@use "theme";
$module: meta.get-module("theme");
.info {
--functions: #{meta.inspect(meta.module-functions($module))};
--mixins: #{meta.inspect(meta.module-mixins($module))};
--variables: #{meta.inspect(meta.module-variables($module))};
font-size: meta.call(map.get(meta.module-functions($module), "rem"), 32px);
} .info {
--functions: ("rem": get-function("rem"));
--mixins: ("stretch": get-mixin("stretch"));
--variables: ("primary": #036);
font-size: 2rem;
} How It Works One module value feeds all three module-* functions.Maps contain function and mixin values, printed as get-function(...) / get-mixin(...).meta.call runs the rem function from the map.Result: 32px becomes 2rem.Example 5 — Unknown Namespace Fails Asking for a module that was never loaded is an error.
$primary: #036 !default;
$radius: 4px !default;
.theme {
color: $primary;
} @use "sass:meta";
@use "theme";
$module: meta.get-module("nope"); Error: There is no module with namespace "nope".
╷
4 │ $module: meta.get-module("nope");
│ ^^^^^^^^^^^^^^^^^^^^^^^
╵
main.scss 4:10 root stylesheet How It Works nope is not a namespace in this file.meta.get-module does not search for stylesheets.Sass stops with a clear error and caret.Fix: @use the module first, or call meta.load(). Edge Cases & Pitfalls Most get-module errors are using the wrong namespace or expecting it to load files.
alias Use the alias after as If you wrote @use "theme" as t, the namespace is t and "theme" will fail.
builtin Built-ins use short names Use "math", not "sass:math".
load get-module never loadsIt only finds modules already loaded in this file. Use meta.load() to load by URL.
scope Namespaces are per file A module loaded by another stylesheet is not visible by namespace here unless you @use it.
Toolchain
Sass Support Part of the first-class module support in recent Dart Sass.
API Status meta.get-module()Dart Sass 1.105+ via @use "sass:meta" Input String matching a @use namespace Return type Module value LibSass / Ruby Sass Not supported
Compile with the Dart Sass CLI .
Remember
Key Takeaways Returns the module value for a @use namespace.
Alias counts: as t means meta.get-module("t").
Built-ins work with names like "math".
Does not load —use meta.load() for that.
One line: call meta.get-module("namespace") when you need a loaded module as a value.
Practice
Compile Notes Practical checklist:
1. @use "sass:meta"
2. @use the module first
3. Pass the namespace (or alias), not the URL
4. Use the value as $module in other meta functions
5. Use meta.load() when the file is not loaded yet Frequently Asked Questions What does Sass meta.get-module() do? meta.get-module($name) returns the module value for a module already loaded in the current file, looked up by its namespace.
What name should I pass? The namespace: "theme" for @use "theme", the alias for @use "theme" as t, and "math" for @use "sass:math". The full sass: URL does not work.
Does meta.get-module() load a stylesheet? No. It only finds modules already loaded with @use. Use meta.load() to load a stylesheet by URL.
What happens with an unknown namespace? Sass stops with an error saying there is no module with that namespace.
What can I do with the module value? Pass it as $module to meta.get-function(), meta.get-mixin(), meta.module-variables(), meta.module-functions(), or meta.module-mixins().
Which Sass version supports meta.get-module()? Dart Sass 1.105 and later. LibSass and Ruby Sass do not provide first-class modules.
CODETOFUN NEWS
Stay Ahead in Tech Get the latest IT news, programming updates, and technology trends directly on your phone.
About the author Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
8 people found this page helpful
Helpful Share Copy link Suggestion