Failed to load .env file ".env": Error: ENOENT: no such file or directory
Hey, Im new to using cloudflare and new to using Hono. I now came across an error that tells me Im missing a .env file, which also should contain some variables. The problem is, idk where I use these and what their values should be. It seems like these should be using system variables instead (Im currently on Windows 10), but I could find an answer online. This only started appearing after I added and tried using Hono.
Here is my code:
The wrangler.toml file:
Franz3•18d ago
The console output:
And the logs:
The goal of this worker would be to serve an rss feed
and when I add
node_compat = true
to the wrangler.toml file, this is the new output:
Console:
Logs
Nico•18d ago
On cloudflare workers you want to use .dev.vars for environment variables
You can use the dotenv package you can access the variables inside context only on c.env
Nico•18d ago
GitHub
GitHub - NicoPlyley/hono-auth: An example app with authentication u...
An example app with authentication using Hono, Drizzle, and D1. Running on CF Workers - NicoPlyley/hono-auth
Nico•18d ago
Here is an example cf workers api
Franz3•17d ago
thanks for the response.
My problem is not that I want to use environment variables in my code.
I have the problem that I cant build/ test my worker locally after I tried using Hono. The error says it is something with environment variables, but I don't use environment variables in my code.
My problem is that I don't understand how to get rid of this error so that it builds/ works locally locally again. I want to fix this bug/ error, not implement environment variables.
Nico•17d ago
Can you show me your package.json
Franz3•17d ago
Here you go:
Nico•17d ago
So your dependency for dotenv is likely causing the issue. Is not compatible with cf workers
It attempts to use file system which is a node specific library that is not supported
Franz3•17d ago
I see
if I remove it, it still doesn't work though
Nico•17d ago
Possible the @hono/node-server is also not working
Make sure you do a bun/npm remove package-name and not just delete those lines of code
Franz3•17d ago
oh ya, someone told me to adding that to fix that bug, idk, I shouldn't need it
Nico•17d ago
Only if your running the application with node you would need that
Franz3•17d ago
I removed the dotenv and node-server with npm and it still fails
Logs:
Nico•17d ago
It still stays dotenv so I wonder if that discord package is using it
Franz3•17d ago
maybe
Nico•17d ago
Did you remove the dotenv on line 3 on index.ts?
Franz3•17d ago
there never was no dotenv, idk what you mean
Nico•17d ago
That’s weird, remove your .wrangler folder and reinstall wrangler
It has a glitch on it somewhere. Does anything in createRssFeed.ts use an external package?
Or better yet I’d delete the node modules and do a fresh install of all packages
Franz3•17d ago
ok, I will try that
Nico•17d ago
Also you don’t have a file on your dev and start commands so
wrangler dev src/index.ts
Also you can update your deploy as well
wrangler deploy --minify src/index.ts
Franz3•17d ago
I removed the wrangler config and the node modules folder, after that I ran these commands:
npm install wrangler --save-dev
npm i feed
npm i discord.js-selfbot-v13
npm i hono
it also doesnt seem like the wrangler config got generated again, I assume thats one part of the problemNico•17d ago
Some package must not be compatible it’s so weird it says in your index file
It just be from the import of the rss file something in there is causing it but it’s not mapping right
Franz3•17d ago
now, idk why, feed is not recognized
Nico•17d ago
Can you comment out everything on rss. Return just a string and then we can verify it’s coming from a package
So don’t import anything on your index
Franz3•17d ago
🥳
Franz3•17d ago
do I have to initialize wrangler with
npx wrangler init
again here?Nico•17d ago
I don’t believe you do
That’s only for setting up a project with a framework I believe
So something in feed has an issue I would try and find an alternative that works on edge platforms
Franz3•17d ago
yes, thats what I assumed, but the wrangler config is not there now
yes, I will look into that. Thanks a lot for the help. What exactly do you mean with "that works on edge platforms" though?
Nico•17d ago
Most edge/serverless platforms don’t use node. They just use the chrome v8 engine. So if a package has node libraries it won’t work
Nico•17d ago
Cloudflare Docs
Node.js compatibility · Cloudflare Workers docs
Implemented Node.js runtime APIs and enablement instructions for your Worker project.
Nico•17d ago
So these are the only ones compatible with cf workers
Nico•17d ago
npm
rss-parser
A lightweight RSS parser, for Node and the browser. Latest version: 3.13.0, last published: a year ago. Start using rss-parser in your project by running
npm i rss-parser
. There are 325 other projects in the npm registry using rss-parser.Nico•17d ago
This appears to work on cf wokers. Since it can run in web it should have any dependencies that require node
Franz3•17d ago
I see, thats why it told me to add
node_compat = true
to the configNico•17d ago
Actually you can use your rss one. I didn’t not realize String Decoder was available on cf workers
So add this to your wrangler.toml
compatibility_flags = [ "nodejs_compat" ]
Franz3•17d ago
I dont have a wrangler.toml. also, thats what I had last time too
Nico•17d ago
Just create on in your root folder
Nico•17d ago
GitHub
starter/templates/cloudflare-workers/wrangler.toml at main · honojs...
Hono starter templates. Contribute to honojs/starter development by creating an account on GitHub.
Nico•17d ago
Copy this one. Just add project name
Franz3•17d ago
done, I still have an issue with importing feed and idk why
Nico•17d ago
What does the issue say
Franz3•17d ago
Cannot find module 'feed' or its corresponding type declarations
Nico•17d ago
Might be an error with the code editor
Sometimes they don’t update
So no guarantee this will make it work because it might still be trying to use dotenv but we’ll see
Franz3•17d ago
ok, so should I try restarting the local dev instance with the rssFeed code included again?
Franz3•17d ago
Nico•17d ago
Did you restart the reload the wrangler.toml file?
Franz3•17d ago
how do I do that?
Nico•17d ago
Just stop wrangler and start it again
The toml file is not hot reloaded
Franz3•17d ago
how do I stop it? isnt that done by using
x
to close the local dev environment and start it again with npx wrangler dev src/index.ts
?
cause that is what I did
else, I dont know how to stop wranglerNico•17d ago
Yup that would be right
Franz3•17d ago
well, then these are the logs I get from that
btw, after restarting the ide, the import error went awai, so thats fine
Nico•17d ago
So it’s working now?
Franz3•17d ago
no
it fails to build
it seems something uses string_decoder which is part of that nodejs server
Nico•17d ago
I’m not sure why it says it’s available
Nico•17d ago
Franz3•17d ago
does that mean the solution would be to find another module with which I can create an atom feed, that doesn't use nodejs server modules? How can I tell if a module is doing that?
Nico•17d ago
Yes that would be best. I sent one earlier that appears to work on cf workers
This one here
If they advertise it works on a browser then it should all work in cf
Franz3•15d ago
Alright, I will give it a shot, thanks a lot
Hey, this is a package to parse an rss feed, but I want to create an rss feed and serve it with my worker. Is it correct that I only have to look out for it being compatible with the chrome v8 engine? This linked rss parser for example, also lists nodejs, so I am confused about how I can tell if a package is compatible or not. Thanks a lot for the help and sorry for the beginner questions
Nico•15d ago
It’s no worries. Most packages don’t advertise it being available for v8. But if they are browser compatible or you use import them using a script tag then they should work on cf workers
Franz3•15d ago
they would have to tell you that they are browser compatible for me to know, or is there another way to tell besides trying it out?
or you use import them using a script tag then they should work on cf workersdo you mean that I can also use nodejs packages if I
import themwith a script tag
? I dont know how I would do that in workers though, as that sounds like html, which would be cf pages if I understand this correctlyNico•15d ago
I’m just meant if they have an option to use a script tag then they don’t use node libraries
Honestly I don’t know if a great way to check there might be a website out there. But I’ll look later today see if I find anything
Franz3•15d ago
amazing, thanks a lot for the help. I will also keep an eye open
Want results from more Discord servers?
More PostsexecutionCtx.waitUntil on write serviceI have a worker that I want to call an external api on, but I want to return a response without awaiDoes Hono JSX do client-side hydration?I.e. are client events like on:click meant to work? And if not, how can it be enabled / done in otheStreamSSE on http2Hi ! It seems that the streamSSE feature is not correctly adapted to work on http2. It adds the follOptional params in hono/clientIt seems that it doesn't support optional params at all.
In hono I can specify optional parameters, Send data to HonoHi, how can i send Request body and file on same route.Client ipHow can I get the client ip, I need it for my rate limiterWhat is the best way to handle the error?What I want is to get the error from server to client using rpc + react query
1. Using `trycatch`
2Running `bun run dev` on a newly created Cloudflare Pages example spits an error```
bun run dev
$ vite
(!) Could not auto-determine entry point from rollupOptions or html files andconnect my hono application endpoints with swagger uihow i can use swagger ui with my hono applicationHow to set "credentials: true" in client side using rpc?I'm using rpc with react query on the client side, this kind of fetching has already credentials: trCookies doesn't processWhen I try to run in my middleware the following
```
setCookie(c, 'test', 'res', { maxAge: 60 * 60 use Context to get vars from wrangler.tomlhow can fix this code. i want to use my openaiApiKey from the wrangler.toml when i create an openai Connect Hono Cloudflare with MongoDBHi. I am using Hono and deploying to Cloudflare. However I am unable to find a way to connect mongodCase insensitive query paramsWe are using hono-zod-openapi to replace an existing API.
Sadly the old API (written in ASP.Net) appPassword hashingHow to hash password?How to setup Hono with Remix/Cloudflare for Vite dev server?From the documentation for Cloudflare Pages, there is an adapter and a plugin, but it is not clear hValidate response objectsUsing the zod validator middleware it is possible to validate params , query, request body like:
``Hono Oauth Provider with JWT issueHey everyone! I'm not sure if this is the right place for me to post about this but recently I wanteDeploy Hono / Bun APII know, I know this is such a newby question but I come from small express apps and other simple ‘clIs there a way to list all request headers ?I have this use case where I am not sure which header key is being sent, I would like to log all hea