Ren Hiyama
Ren Hiyama•16mo ago

Deno cannot import mainfile by reading from package.json

deno 1.36.0 (release, x86_64-unknown-linux-gnu) v8 11.6.189.12 typescript 5.1.6
No description
9 Replies
Ren Hiyama
Ren HiyamaOP•16mo ago
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"
}
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.
Deno AI Helper
Deno AI Helper•16mo ago
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"
}
}
{
"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!"));
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
deno run --allow-env --allow-sys main.ts
Or execute package.json scripts via deno task:
deno task dev
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. 🦕
Ren Hiyama
Ren HiyamaOP•16mo ago
I'm using node compat to do the job, is that not possible?
marvinh.
marvinh.•16mo ago
@renhiyama.gg does the error occur in latest deno too? iirc there were a couple of fixes in there regarding npm support
Ren Hiyama
Ren HiyamaOP•16mo ago
nixos still didnt update deno to 1.37.0 ... lemme quickly try it in ubuntu
Ren Hiyama
Ren HiyamaOP•16mo ago
tried docker image, it is more buggy there, any wierd reasons? sudo docker run -it --init -p 3000:3000 -v $PWD:/app denoland/deno:alpine-1.37.0 run -A npm:reejs@0.13.4 -v incase u are interested
No description
marvinh.
marvinh.•16mo ago
that sounds like process.env isn't populated
Ren Hiyama
Ren HiyamaOP•16mo ago
maybe, cant read that code so cant confirm really. but 1.36.0 works fine (except the issue im currently having)
marvinh.
marvinh.•16mo ago
maybe best to file an issue in the deno tracker. Sounds like something is wrong here