Stéphane
Stéphane6mo ago

Fresh - Error while running deno run on the built _fresh directory

Hi, I installed the latest version of Deno yesterday on Manjaro using the install.sh script. I then created a fresh (haha) fresh project. I noticed that the cli task was not happy because it uses the --unstable flag which is not valid anymore. Then I used the build task that successfully created a _fresh folder, but when I tried deno run -A _fresh/main.js I got the following error :
error: Uncaught (in promise) ReferenceError: history is not defined
at file:///home/stephane/deno/fresh-project/_fresh/main.js:1:7893
error: Uncaught (in promise) ReferenceError: history is not defined
at file:///home/stephane/deno/fresh-project/_fresh/main.js:1:7893
Is it an expected behaviour ?
5 Replies
Deno AI Helper
Deno AI Helper6mo ago
I wasn't able to find the answer to your question in the official Deno documentation. However, based on the error message you've provided, it seems like there might be a reference to a history object that is not defined within the context of your Deno application. The history object is typically available in the context of a web browser and is used for manipulating the browser session history. If main.js is trying to access the history object outside of a browser context, such as in a Deno runtime, it would indeed result in a ReferenceError. Please note that this advice is not based on the Deno documentation, and I would advise you to double-check the accuracy of this advice. It's possible that the code within main.js is intended to be run in the context of a browser, or there may be a polyfill or abstraction that is supposed to provide a history object that isn't being included or imported correctly. If main.js is part of the output from the Fresh framework and you haven't modified it, this might be an issue with the framework itself or with how the project is set up. In that case, you might want to check the Fresh framework's issue tracker or discussions to see if others have encountered a similar problem or to report a new issue.
marvinh.
marvinh.6mo ago
The files in the _fresh directory are the compiled assets meant to be run in the browser. They are not intended to be run in Deno. To start your Fresh application run:
# CORRECT
deno run -A main.ts
# WRONG: Tries to run browser entry
deno run -A _fresh/main.js
# CORRECT
deno run -A main.ts
# WRONG: Tries to run browser entry
deno run -A _fresh/main.js
Stéphane
StéphaneOP6mo ago
ah ok, so it can be run locally ? Or is meant for deno deploy only ? It was not clear to me what I can do with the compiled assets :/
marvinh.
marvinh.6mo ago
Yes it can be run locally. When you run deno task build Fresh creates the optimized assets for the browser in _fresh/ and when you run deno run -A main.ts those will be picked up. You should see some sort of "using snapshot from XY" message when that happens
Stéphane
StéphaneOP6mo ago
ah ok, didn't get it like that, thanks for clarifying 🙂 I played with Astro SSG before and forgot that it's completely different 😅 Marking the topic as solved, thanks 🙂

Did you find this page helpful?