#Deno build/run

13 messages · Page 1 of 1 (latest)

steady spindleBOT
#

The error message you're seeing suggests that Deno is having trouble resolving the import path "#utils/Function.js". Deno uses a different module resolution strategy than Node.js and requires import paths to be explicit. This means that you need to include the full file path, including the extension, in your import statements.

In Deno, you can't use import paths that start with "#" unless they are defined in an import map. Import maps allow you to remap the location of dependencies from their original location to a new one. This can be useful for using bare specifiers, like "#utils/Function.js", instead of relative or absolute file paths.

Here's an example of how you might define this in an import map:

{
  "imports": {
    "#utils/": "./utils/"
  }
}

In this example, any import that starts with "#utils/" would be mapped to the "./utils/" directory.

You can specify the import map when running your program with the --import-map flag, like so:

$ deno run --import-map=import_map.json ./mod.ts

If you're still having trouble, could you provide more information about your project structure and how your import statements are set up? That would help me give more specific advice. 🦕

gentle owl
steady spindleBOT
#

Deno does not support import maps in package.json or tsconfig.json. Instead, Deno uses a deno.json configuration file for import maps.

Here's an example of how you might define this in a deno.json:

{
  "imports": {
    "#utils/": "./utils/"
  }
}

In this example, any import that starts with "#utils/" would be mapped to the "./utils/" directory.

You can specify the import map when running your program with the --import-map flag, like so:

$ deno run --import-map=import_map.json ./mod.ts

If you're still having trouble, could you provide more information about your project structure and how your import statements are set up? That would help me give more specific advice. 🦕

gentle owl
steady spindleBOT
#

If you set the imports in deno.json, you are essentially creating an import map within the deno.json file itself. This means you don't need a separate import_map.json file.

When you run your program, you can use the --import-map flag to specify the deno.json file as your import map. Here's how you might do that:

$ deno run --import-map=deno.json ./mod.ts

In this command, deno.json is serving as your import map. This is possible because, as of Deno 1.30, the deno.json configuration file can act as an import map for resolving bare specifiers.

So, if you have defined your imports in deno.json, you don't need to pass a separate import_map.json file. Instead, you pass deno.json as your import map.

gentle owl
steady spindleBOT
#

The error message you're seeing suggests that Deno is having trouble resolving the import path "node:url". This is because Deno does not support Node.js-style imports out of the box.

However, Deno does provide built-in support for some Node.js modules, and you can use the node: prefix to import these modules. For example, you can do import { readFileSync } from "node:fs"; to import the readFileSync function from Node.js's fs module.

If you're trying to import a module that is not built into Deno, you'll need to use an import map to tell Deno where to find the module. Here's an example of how you might do this:

{
  "imports": {
    "url": "https://deno.land/[email protected]/node/url.ts"
  }
}

In this example, any import that starts with "url" would be mapped to the "https://deno.land/[email protected]/node/url.ts" URL.

You can specify the import map when running your program with the --import-map flag, like so:

$ deno run --import-map=import_map.json ./mod.ts

If you're still having trouble, could you provide more information about your project structure and how your import statements are set up? That would help me give more specific advice. 🦕

gentle owl
steady spindleBOT
steady spindleBOT
#

In Deno, to get the current working directory, you should use Deno.cwd() instead of process.cwd(). Here's how you can do it:

const currentWorkingDirectory = Deno.cwd();
console.log(currentWorkingDirectory);

This will print the current working directory to the console.

Please note that accessing the current working directory requires the --allow-read permission. So, you need to include this flag when running your Deno program. Here's how you can do that:

deno run --allow-read ./mod.ts

In this command, ./mod.ts is the path to your Deno program. Replace it with the actual path to your program.

If you're still having trouble, could you provide more information about your project structure and how your code is set up? That would help me give more specific advice. 🦕

earnest cairn
#

@gentle owl could you open an issue in the repository with your reproduction code?

gentle owl