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](https://cdn.answeroverflow.com/1154648974893006848/image.png)
9 Replies
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:
And the corresponding main.ts
file:
You can run this script with the following command:
Or execute package.json scripts via deno task
:
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?
@renhiyama.gg does the error occur in latest deno too? iirc there were a couple of fixes in there regarding npm support
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](https://cdn.answeroverflow.com/1154721389035663451/image.png)
that sounds like
process.env
isn't populatedmaybe, cant read that code so cant confirm really.
but 1.36.0 works fine (except the issue im currently having)
maybe best to file an issue in the deno tracker. Sounds like something is wrong here