Deno AI Helper
Deno AI Helper
DDeno
Created by Руслан Сахаутдинов on 8/8/2024 in #help
timeOrigin = undefined on Deno Deploy
I wasn't able to find the answer to your question in the official Deno documentation. However, based on the information you've provided, it seems that performance.timeOrigin is returning undefined, which is not expected behavior as performance.timeOrigin should return the time value representing the start time of the performance measurement. Since performance.timeOrigin is undefined, attempting to use it as a timestamp for a Date object would indeed result in a RangeError because Date expects a valid timestamp. You mentioned that using Date.now() works, which is a good alternative to get the current timestamp. performance.now() is also working for you, which is great for measuring time intervals with high resolution. The advice I'm providing is not based on the Deno documentation, so please double-check the accuracy of this advice. If performance.timeOrigin is not behaving as expected on Deno Deploy, it might be a platform-specific issue or a bug. You might want to consider reporting this behavior to the Deno Deploy team or checking if there are any open issues related to this on the Deno issue tracker. In the meantime, using Date.now() as you have done is a valid workaround for getting the current timestamp. If you need a high-resolution start time for performance measurements, you might need to establish your own baseline using Date.now() or performance.now() at the start of your script.
2 replies
DDeno
Created by Óscar on 8/7/2024 in #help
Detect when the event loop is finished in a Worker
I wasn't able to find the answer to your question in the official Deno documentation. However, based on your message, there doesn't seem to be any obvious syntax errors or mistakes. It's important to note that the behavior you're describing—waiting for all timers to close and unawaited promises to settle before terminating—is not something that is typically exposed through a standard API in JavaScript environments. In Node.js, for instance, the process stays alive as long as there are pending asynchronous operations, but there isn't a built-in way to "detect" when the event loop is "clean" without manually tracking the operations. In Deno, and specifically within a Worker, you might need to implement your own tracking of asynchronous operations if you want to achieve a similar effect. This could involve keeping count of active operations and only calling self.close() when that count reaches zero. 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, possibly by experimenting with your code or seeking further insights from the Deno community.
4 replies
DDeno
Created by Berserkr [yol] on 8/7/2024 in #help
Can Deno automatically install peerdeps like NPM does?
I wasn't able to find the answer to your question in the official Deno documentation. However, based on your message, it's important to note that Deno does not have a package.json file like npm, and it does not handle dependencies in the same way as npm does. Deno imports modules directly from URLs, and it caches them upon the first import. There is no direct equivalent to npm's automatic handling of peer dependencies in Deno. Since Deno does not have a built-in mechanism for automatically managing peer dependencies like npm, you would typically need to ensure that all required dependencies are explicitly imported in your code. If your framework relies on peer dependencies, you may need to document the required imports so that users of your framework can include them in their projects. 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. For a recommended solution, you might want to explore community practices or reach out to the Deno community for patterns that others have adopted when dealing with similar situations.
2 replies
DDeno
Created by Jan on 8/6/2024 in #help
How do I publish a Rust CLI on JSR
I wasn't able to find the answer to your question in the official Deno documentation. However, based on your message, it seems like you're looking to make your Rust CLI available to TypeScript developers, potentially through the Deno ecosystem. While I can't provide specific guidance on publishing a Rust CLI on JSR (JavaScript Registry), I can tell you that Deno has its own third-party module registry called Deno.land/x, where you can publish Deno modules. If you want to make your Rust CLI available to Deno users, you would typically compile your Rust code to a WebAssembly module or create a plugin, and then publish it on Deno.land/x. 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. For the most accurate and up-to-date information on publishing modules to Deno.land/x, please refer to the official Deno documentation or the Deno community for further assistance.
4 replies
DDeno
Created by Nermal on 8/6/2024 in #help
Error: Cannot find module '@alloc/quick-lru'
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 you're trying to import a module named @alloc/quick-lru which cannot be found. In Deno, importing modules is typically done by specifying the full URL of the module, unlike in Node.js where you might use package names like @alloc/quick-lru. If you're trying to import a third-party module in Deno, ensure that you are using the correct URL for the import statement. Please note that this advice is not based on the Deno documentation, and I would recommend double-checking the accuracy of this advice and ensuring that you are following the correct import conventions for Deno. If @alloc/quick-lru is a Node.js package, it will not be directly compatible with Deno as Deno does not use the Node.js module resolution system. You would need to find a Deno-compatible module or a CDN that provides an ESM version of the package.
6 replies
DDeno
Created by Halvard on 8/6/2024 in #help
What is the correct way of importing members of a workspace?
carefully design your modules to ensure that the dependencies are one-way wherever possible, or that the circular dependencies do not cause issues during runtime. 🦕
4 replies
DDeno
Created by Halvard on 8/6/2024 in #help
What is the correct way of importing members of a workspace?
In a Deno workspace, you can set up multiple modules and import functions from one module into another using "bare specifiers" that are defined in the deno.json configuration files of each module. Here's how you can do it according to the documentation: 1. Define a workspace: In your root deno.json, you define a workspace by specifying its members, which are directories expected to have their own deno.json(c) and/or package.json files.
{
"workspace": ["./add", "./subtract"]
}
{
"workspace": ["./add", "./subtract"]
}
2. Name your workspace members: In each member directory, you should have a deno.json file where you define a "name" field. This name is used to reference the workspace member throughout your workspace. For example, in the add module, you would have:
{
"name": "@scope/add",
"version": "0.1.0",
"exports": "./mod.ts"
}
{
"name": "@scope/add",
"version": "0.1.0",
"exports": "./mod.ts"
}
And in the subtract module:
{
"name": "@scope/subtract",
"version": "0.3.0",
"exports": "./mod.ts"
}
{
"name": "@scope/subtract",
"version": "0.3.0",
"exports": "./mod.ts"
}
3. Import using bare specifiers: In your code, you can then import functions from these modules using the names defined in their respective deno.json files. For instance, in your main.ts:
import { add } from "@scope/add";
import { subtract } from "@scope/subtract";
import { add } from "@scope/add";
import { subtract } from "@scope/subtract";
Regarding circular imports, the documentation does not explicitly mention restrictions on circular imports within a workspace. However, it's generally a good practice to avoid circular dependencies as they can lead to complex dependency graphs and potential runtime issues. The Deno style guide, while not directly addressing workspaces, advises minimizing dependencies and avoiding circular imports to keep internal dependencies simple and manageable. If you need to have modules that depend on each other, you should
4 replies
DDeno
Created by vtsfly on 8/6/2024 in #help
Using Deno.KV outside deno deploy environment, limit problem
I wasn't able to find the answer to your question in the official Deno documentation. However, based on the code snippet you provided, I can offer some general advice, but please note that this advice is not based on the Deno documentation, and I advise you to double-check the accuracy of the advice given. In your code, you are using kv.watch within an infinite loop, which could potentially lead to a high number of requests to the Deno.KV service. If the kv.watch method is implemented in a way that it polls the server at a high frequency, this could be the reason why you are hitting rate limits. One thing to consider is whether the kv.watch method is designed to be used in a long-polling fashion or if it's expected to be called less frequently. If it's the latter, you might need to implement some form of back-off strategy or limit the frequency of your requests to avoid hitting rate limits. Additionally, ensure that your cancel function in the ReadableStream is properly closing any open connections or stopping the watch operation to prevent unnecessary requests when the client disconnects. Since this is not based on the official documentation, I recommend reaching out to the Deno community or checking the source code of the Deno.KV service if it's available to you, to understand the expected usage patterns and rate limits when not running within the Deno Deploy environment.
2 replies
DDeno
Created by wuX4an on 8/3/2024 in #help
Is it possible to use Yarn with Deno?
Yes, you can use Yarn with Deno's JavaScript Registry (JSR). The documentation states that JSR packages can be seamlessly consumed by any tool that uses node_modules/ folders, which includes Yarn. You can incrementally adopt JSR packages in your Node projects, and you can use your favorite npm-compatible package manager like Yarn, or pnpm with JSR. 🦕 Keep in mind that while you can use Yarn with JSR, Deno itself has its own module resolution system that does not rely on node_modules/ or package managers like Yarn. Deno's cache system is designed to work with its own module resolution, which fetches and caches modules based on URLs.
2 replies
DDeno
Created by kindly on 8/3/2024 in #help
Vue example doesn't work out of the box
applied to the module. Check if the Vue-related modules you're using have such hints and follow them accordingly. If you've tried these steps and are still facing issues, could you provide more details about the specific error messages you're encountering? This will help in diagnosing the problem further. Remember, Deno is quite strict about module specifiers and types, so it's important to ensure everything is correctly referenced and imported.
9 replies
DDeno
Created by kindly on 8/3/2024 in #help
Vue example doesn't work out of the box
Hello! I'm glad to hear you're giving Deno a try with Vue. 🦕 If you're encountering issues with types not working out of the box, there are a few things you can check and try: 1. Ensure all dependencies are correctly imported: Make sure that all the necessary dependencies are imported with their full URLs and that they include the .ts extension if they are TypeScript modules. Deno requires explicit specifiers, so this is a common source of issues. 2. Check for TypeScript configuration: If there's a TypeScript configuration file (tsconfig.json), ensure it's correctly set up and that Deno is using it by specifying the --config=path/to/file flag when running your commands. 3. Use triple-slash directives: The documentation mentions that you can use triple-slash directives to couple the library settings with the code itself. This can help Deno understand which type definitions to apply to your script. For example, you might need to add something like this at the top of your entry point file:
/// <reference lib="deno.window" />

/// <reference lib="deno.window" />

This instructs Deno to apply the built-in Deno type definitions for a window context. 4. Check for any type declaration files: If you have .d.ts files that provide types for your JavaScript modules, make sure they are correctly referenced either through triple-slash directives or included in your TypeScript configuration file under the compilerOptions.types array. 5. Run deno cache: Sometimes running deno cache on your entry file can help download and cache the dependencies with their type definitions, which might resolve some type issues. 6. Look for any available type hints: Some modules might provide compiler hints using @ts-types comments to specify which types should be
9 replies
DDeno
Created by octo3. on 8/3/2024 in #help
not found ctx.data
I wasn't able to find the answer to your question in the official Deno documentation. However, based on the code snippet you've provided, it seems that you are trying to access ctx.data in your default function Home, but ctx.data is not being set in the GET handler. In the GET handler, you are passing an object with a message property to ctx.render(), but this does not automatically set ctx.data. The ctx.render() function is used to render a page with the given data, but it does not modify the ctx object itself. If you want to pass data to the Home component, you should ensure that the data is being set on the context object properly, which is typically done within the handler functions. However, without further documentation or context, I cannot provide a definitive solution. 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 there might be a specific way to handle context data in Fresh that is not covered here.
3 replies
DDeno
Created by aostiles on 8/1/2024 in #help
Enabling Web APIs embedded
Apologies for the confusion. In Rust, the last expression in a function is used as the return value and should not have a semicolon if it's the value you wish to return. Therefore, the original implementation of your allow_hrtime function was correct without the semicolon:
fn allow_hrtime(&mut self) -> bool {
false
}
fn allow_hrtime(&mut self) -> bool {
false
}
If TextEncoder is not available at runtime in your JavaScript code, it's possible that the necessary extension to enable TextEncoder is not being included or properly initialized in your Deno runtime. The TextEncoder API is part of the deno_web crate, which seems to be included in your extensions. Please ensure that all necessary dependencies and extensions are correctly initialized. If the problem persists, it might be beneficial to review the official Deno documentation or seek assistance from the Deno community, as there might be additional context or steps required that are not covered in the code snippet you've provided.
4 replies
DDeno
Created by ginpacc on 8/2/2024 in #help
node:worker_threads "Module not found"
I wasn't able to find the answer to your question in the official Deno documentation. However, based on the message you've provided, it seems like you might be referencing Node.js-specific functionality (node:worker_threads) which is not available in Deno. Deno has its own way of handling worker threads using the Worker API. If you're trying to use Node.js-style worker threads in Deno, that would not work because Deno does not support Node.js modules out of the box. Instead, you should use Deno's built-in Worker API. Here's a basic example of how to use workers in Deno:
// main.ts
const worker = new Worker(new URL("worker.ts", import.meta.url).href, { type: "module" });
worker.postMessage("Hello, worker!");

// worker.ts
self.onmessage = (e) => {
console.log("Received from main script:", e.data);
self.close();
};
// main.ts
const worker = new Worker(new URL("worker.ts", import.meta.url).href, { type: "module" });
worker.postMessage("Hello, worker!");

// worker.ts
self.onmessage = (e) => {
console.log("Received from main script:", e.data);
self.close();
};
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 and consult the Deno documentation or community for further assistance.
4 replies
DDeno
Created by aostiles on 8/1/2024 in #help
Enabling Web APIs embedded
I wasn't able to find the answer to your question in the official Deno documentation. However, based on the code snippet you provided, I noticed that there might be a syntax error in your Rust implementation. The allow_hrtime function is missing a semicolon at the end of the false statement. In Rust, expressions in function bodies should end with a semicolon to indicate that they are statements. Here's the corrected version of the function:
fn allow_hrtime(&mut self) -> bool {
false;
}
fn allow_hrtime(&mut self) -> bool {
false;
}
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. If the issue persists after making this correction, it could be related to other parts of your setup or code that are not included in your message.
4 replies
DDeno
Created by jon on 8/1/2024 in #help
Automate Export+Import when using deps.ts pattern in VSCode/LSP
I wasn't able to find the answer to your question in the official Deno documentation. However, based on your message, it seems like you're looking for a way to enhance the functionality of the Deno extension for Visual Studio Code to support a more automated way of managing imports from a centralized deps.ts file. As of my knowledge cutoff date, the Deno extension for VSCode does not provide a feature to automatically add new exports to deps.ts and then update imports elsewhere in your project to use that centralized module. The "Quick Fix" feature in VSCode typically suggests imports based on existing exports, and it does not modify other files to add exports that are not already present. Since this advice is not based on the Deno documentation, I recommend double-checking the accuracy of this information and exploring the possibility of custom extensions or scripts that could assist with this task. Additionally, you might want to keep an eye on updates to the Deno extension for VSCode or reach out to the community to see if there are any plans or existing solutions for this kind of functionality.
2 replies
DDeno
Created by Hasan Rimawi on 7/31/2024 in #help
Deno Install <>
The deno install subcommand is used to install executable scripts from URLs into your system. Here's how you can use it according to the documentation: 1. To install a script, you run deno install with the necessary permissions and the URL of the script. For example:
deno install --allow-net --allow-read https://deno.land/std/http/file_server.ts

deno install --allow-net --allow-read https://deno.land/std/http/file_server.ts

This command will compile the script and create an executable shell script that invokes deno with the specified permissions and main module. 2. If you want to change the name of the executable, you can use the -n or --name option:
deno install --allow-net --allow-read -n serve https://deno.land/std/http/file_server.ts

deno install --allow-net --allow-read -n serve https://deno.land/std/http/file_server.ts

This will install the script with the custom name serve. 3. You can also specify a different installation root using the --root option:
deno install --allow-net --allow-read --root /usr/local https://deno.land/std/http/file_server.ts

deno install --allow-net --allow-read --root /usr/local https://deno.land/std/http/file_server.ts

Remember to add the installation root's bin directory to your system's PATH if it's not already there. 4. When installing scripts, you must specify the permissions that the script will need at runtime. For example, if you want the script to run with network and read permissions and bind to port 8080, you would do:
deno install --allow-net --allow-read https://deno.land/std/http/file_server.ts -- -p 8080

deno install --allow-net --allow-read https://deno.land/std/http/file_server.ts -- -p 8080

For more detailed examples and usage, you can refer to the Deno documentation on script installer. 🦕
6 replies
DDeno
Created by rhymbit on 7/31/2024 in #help
Google Cloud Storage library error inside docker, but outside on my pc it's working fine.
assistance from the community or the maintainers of the @google-cloud/storage library for more Docker-specific troubleshooting.
6 replies
DDeno
Created by rhymbit on 7/31/2024 in #help
Google Cloud Storage library error inside docker, but outside on my pc it's working fine.
I wasn't able to find the answer to your question in the official Deno documentation. However, based on the information you've provided in your message, I can offer some general advice. Firstly, it's important to note that the @google-cloud/storage library you're using is an npm package, which is designed to be used with Node.js, not Deno. Deno does not use npm packages directly as it has a different module system. If you're trying to use an npm package within Deno, you would typically need to use a compatibility layer or find an equivalent Deno module. In your Dockerfile, you're using a Node.js base image and then copying Deno into it. This setup can work, but it's not typical for Deno applications. Deno applications usually don't require Node.js, and vice versa. Here are a few things you might want to check or try: 1. Ensure that the environment variables and credentials required by the @google-cloud/storage library are correctly set up in your Docker container. These might include GOOGLE_APPLICATION_CREDENTIALS or other related environment variables. 2. Verify that the network configuration in your Docker container allows for outbound connections to Google Cloud Storage. 3. If you're using Deno, consider looking for a Deno module that provides Google Cloud Storage functionality, or use the Deno FFI (Foreign Function Interface) to interact with the Google Cloud Storage C++ client libraries. 4. If you need to use the @google-cloud/storage npm package, you might want to stick with a Node.js environment rather than trying to integrate it with Deno. Please note that this advice is not based on the Deno documentation, and I would advise you to double-check the accuracy of the advice given. If you continue to experience issues, you may want to seek
6 replies