#Deno cannot import mainfile by reading from package.json
11 messages · Page 1 of 1 (latest)
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.
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. 🦕
I'm using node compat to do the job, is that not possible?
@prime zenith does the error occur in latest deno too? iirc there were a couple of fixes in there regarding npm support
nixos still didnt update deno to 1.37.0 ... lemme quickly try it in ubuntu
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
that sounds like process.env isn't populated