问题答案 12026年5月27日 03:37
How to import a module inside the Deno REPL?
The method of importing modules in Deno's REPL (Read-Eval-Print Loop) environment is similar to that in Deno scripts, but there are specific considerations to note. Below are the detailed steps and examples:Step 1: Start Deno REPLFirst, open your terminal and enter to launch the Deno REPL environment. For example:Step 2: Use the import statement to import modulesIn Deno REPL, you can directly use the statement to import modules. There are two primary approaches: importing directly from a URL or from a local file.Example 1: Importing from a URLSuppose you want to import a module providing date functionality, such as the library, you can directly import it using its URL:Then, you can use the function to format dates:Example 2: Importing from a local fileIf you have a local module, such as a file named , you can import it as follows:Assuming the content of is:Then, in the REPL, you can use:NotesEnsure the path or URL is correct; otherwise, the import will fail.If the module uses TypeScript, Deno automatically handles compilation.Importing modules directly in the REPL may introduce a slight delay due to the need to download and compile the module.By following these steps, you can flexibly import any required modules in Deno's REPL environment, offering developers significant convenience and flexibility.