#Deno cannot import mainfile by reading from package.json

11 messages · Page 1 of 1 (latest)

prime zenith
#

deno 1.36.0 (release, x86_64-unknown-linux-gnu)
v8 11.6.189.12
typescript 5.1.6

#
TypeError: Directory import /home/ren/coding/frontend/node_modules/@reejs/imports is not supported resolving import from file:///home/ren/coding/frontend/.reejs/serve/6a3aba.js
Did you mean to import index.js within the directory?
  Caused by:
    Is a directory (os error 21)
    at async file:///home/ren/coding/frontend/node_modules/.deno/reejs@0.13.4/node_modules/reejs/src/cli/cmds/packit.js:408:30 {
  code: "ERR_MODULE_NOT_FOUND"
}
#

this problem doesnt exist on nodejs though. package.json has "main" field which says index.js is the main file. and index.js file exists.

thin groveBOT
#

According to the documentation, Deno does support resolving dependencies based on a package.json file in the current or ancestor directories. This is similar to how Node.js resolves dependencies. However, we recommend using import maps with deno.json.

Here's an example of how you can use a package.json file with Deno:

{
  "name": "@deno/my-example-project",
  "description": "An example app created with Deno",
  "type": "module",
  "scripts": {
    "dev": "deno run --allow-env --allow-sys main.ts"
  },
  "dependencies": {
    "chalk": "^5.2"
  }
}

And the corresponding main.ts file:

import chalk from "chalk";

console.log(chalk.green("Hello from Deno!"));

You can run this script with the following command:

deno run --allow-env --allow-sys main.ts

Or execute package.json scripts via deno task:

deno task dev

Please note that importing via a bare specifier (ex. import { readFileSync } from "fs";) without an import map is not supported. If you attempt to do so and the bare specifier matches a Node.js built-in module not found in an import map, Deno will provide a helpful error message asking if you meant to import with the node: prefix. 🦕

prime zenith
#

I'm using node compat to do the job, is that not possible?

proper zephyr
#

@prime zenith does the error occur in latest deno too? iirc there were a couple of fixes in there regarding npm support

prime zenith
prime zenith
proper zephyr
prime zenith
#

maybe, cant read that code so cant confirm really.

#

but 1.36.0 works fine (except the issue im currently having)