Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
⌘K
Up or down tonavigateEnter toselectEscape toclose
On this page

Module metadata

ConceptsJump to heading

  • import.metacan provide information on the context of the module.
  • The booleanimport.meta.mainwill let you know if the current module is the program entry point.
  • The stringimport.meta.urlwill give you the URL of the current module.
  • The stringimport.meta.filenamewill give you the fully resolved path to the current module.For localmodules only.
  • The stringimport.meta.dirnamewill give you the fully resolved path to the directory containing the currentmodule.For local modules only.
  • Theimport.meta.resolveallows you to resolve specifier relative to the current module. This functiontakes into account an import map (if one was provided on startup).
  • The stringDeno.mainModulewill give you the URL of the main module entry point, i.e. the module invokedby the deno runtime.

ExampleJump to heading

The example below uses two modules to show the difference betweenimport.meta.url,import.meta.main andDeno.mainModule. In this example,module_a.ts is the main module entry point:

module_b.ts
exportfunctionoutputB(){console.log("Module B's import.meta.url",import.meta.url);console.log("Module B's mainModule url", Deno.mainModule);console.log("Is module B the main module via import.meta.main?",import.meta.main,);}
module_a.ts
import{ outputB}from"./module_b.ts";functionoutputA(){console.log("Module A's import.meta.url",import.meta.url);console.log("Module A's mainModule url", Deno.mainModule);console.log("Is module A the main module via import.meta.main?",import.meta.main,);console.log("Resolved specifier for ./module_b.ts",import.meta.resolve("./module_b.ts"),);}outputA();console.log("");outputB();

Ifmodule_a.ts is located in/home/alice/deno then the output ofdeno run --allow-read module_a.ts is:

Module A's import.meta.url file:///home/alice/deno/module_a.tsModule A's mainModule url file:///home/alice/deno/module_a.tsIs module A the main module via import.meta.main? trueResolved specifier for ./module_b.ts file:///home/alice/deno/module_b.tsModule B's import.meta.url file:///home/alice/deno/module_b.tsModule B's mainModule url file:///home/alice/deno/module_a.tsIs module B the main module via import.meta.main? false

Did you find what you needed?

What can we do to improve this page?

If provided, you'll be @mentioned in the created GitHub issue

Privacy policy

[8]ページ先頭

©2009-2026 Movatter.jp