Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 BUG: ✘ [ERROR] triggers.map is not a function #5806

Closed
anderskitson opened this issue May 12, 2024 · 1 comment
Closed

🐛 BUG: ✘ [ERROR] triggers.map is not a function #5806

anderskitson opened this issue May 12, 2024 · 1 comment
Labels
bug Something that isn't working

Comments

@anderskitson
Copy link

Which Cloudflare product(s) does this pertain to?

Workers for Platforms, Wrangler core

What version(s) of the tool(s) are you using?

"wrangler": "^3.0.0"

What version of Node are you using?

20.10.0

What operating system and version are you using?

Mac Sonoma 14.3 (23D56)

Describe the Bug

Observed behavior

On npm run deploy I get the error triggers.map is not a function.

Expected behavior

I would have expected the app to deploy.

Steps to reproduce

This is my basic project index.js file

/**
 * This is a template for a Scheduled Worker that updates TLD data from DNSimple
 * and stores it in Redis. The worker is triggered based on the schedule defined
 * in the wrangler.toml configuration.
 */

export default {
    async scheduled(event, env, ctx) {
        event.waitUntil(handleScheduledEvent());
        console.log(`Update triggered at ${event.scheduledTime}`);
    },
};


async function handleScheduledEvent() {
    const dnsimpleApi = 'https://api.dnsimple.com/v2/tlds';

    try {
        // Fetching TLD data from DNSimple
        const response = await fetch(dnsimpleApi);
        const jsonData = await response.json();
        const tlds = jsonData.data;

        // Update each TLD in Redis
        for (const tld of tlds) {
			await env.KV_TLD_SYNC.put("tld", tld.tld);       
        }
    } catch (error) {
        console.error('Error in scheduled event:', error);
    }
}

This is my Wrangler.toml file

#:schema node_modules/wrangler/config-schema.json
name = "tld-sync"
main = "src/index.js"
compatibility_date = "2024-05-02"

# Cron Triggers
# Docs: https://developers.cloudflare.com/workers/platform/triggers/cron-triggers/
# Configuration: https://developers.cloudflare.com/workers/wrangler/configuration/#triggers
[triggers]
crons = "0 * * * *"  # This sets the worker to run at the start of every hour

# Automatically place your workloads in an optimal location to minimize latency.
# If you are running back-end logic in a Worker, running it closer to your back-end infrastructure
# rather than the end user may result in better performance.
# Docs: https://developers.cloudflare.com/workers/configuration/smart-placement/#smart-placement
# [placement]
# mode = "smart"

# Variable bindings. These are arbitrary, plaintext strings (similar to environment variables)
# Docs:
# - https://developers.cloudflare.com/workers/wrangler/configuration/#environment-variables
# Note: Use secrets to store sensitive data.
# - https://developers.cloudflare.com/workers/configuration/secrets/
# [vars]
# MY_VARIABLE = "production_value"

# Bind the Workers AI model catalog. Run machine learning models, powered by serverless GPUs, on Cloudflare’s global network
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#workers-ai
# [ai]
# binding = "AI"

# Bind an Analytics Engine dataset. Use Analytics Engine to write analytics within your Pages Function.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#analytics-engine-datasets
# [[analytics_engine_datasets]]
# binding = "MY_DATASET"

# Bind a headless browser instance running on Cloudflare's global network.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#browser-rendering
# [browser]
# binding = "MY_BROWSER"

# Bind a D1 database. D1 is Cloudflare’s native serverless SQL database.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#d1-databases
# [[d1_databases]]
# binding = "MY_DB"
# database_name = "my-database"
# database_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

# Bind a dispatch namespace. Use Workers for Platforms to deploy serverless functions programmatically on behalf of your customers.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#dispatch-namespace-bindings-workers-for-platforms
# [[dispatch_namespaces]]
# binding = "MY_DISPATCHER"
# namespace = "my-namespace"

# Bind a Durable Object. Durable objects are a scale-to-zero compute primitive based on the actor model.
# Durable Objects can live for as long as needed. Use these when you need a long-running "server", such as in realtime apps.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#durable-objects
# [[durable_objects.bindings]]
# name = "MY_DURABLE_OBJECT"
# class_name = "MyDurableObject"

# Durable Object migrations.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#migrations
# [[migrations]]
# tag = "v1"
# new_classes = ["MyDurableObject"]

# Bind a Hyperdrive configuration. Use to accelerate access to your existing databases from Cloudflare Workers.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#hyperdrive
# [[hyperdrive]]
# binding = "MY_HYPERDRIVE"
# id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

# Bind a KV Namespace. Use KV as persistent storage for small key-value pairs.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#kv-namespaces
# [[kv_namespaces]]
# binding = "REDACTED"
# id = "redacted"

# Bind an mTLS certificate. Use to present a client certificate when communicating with another service.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#mtls-certificates
# [[mtls_certificates]]
# binding = "MY_CERTIFICATE"
# certificate_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

# Bind a Queue producer. Use this binding to schedule an arbitrary task that may be processed later by a Queue consumer.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#queues
# [[queues.producers]]
# binding = "MY_QUEUE"
# queue = "my-queue"

# Bind a Queue consumer. Queue Consumers can retrieve tasks scheduled by Producers to act on them.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#queues
# [[queues.consumers]]
# queue = "my-queue"

# Bind an R2 Bucket. Use R2 to store arbitrarily large blobs of data, such as files.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#r2-buckets
# [[r2_buckets]]
# binding = "MY_BUCKET"
# bucket_name = "my-bucket"

# Bind another Worker service. Use this binding to call another Worker without network overhead.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#service-bindings
# [[services]]
# binding = "MY_SERVICE"
# service = "my-service"

# Bind a Vectorize index. Use to store and query vector embeddings for semantic search, classification and other vector search use-cases.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#vectorize-indexes
# [[vectorize]]
# binding = "MY_INDEX"
# index_name = "my-index"

I don't see why this error is happening. Any help would be greatly appreciated.

Please provide a link to a minimal reproduction

No response

Please provide any relevant error logs

triggers.map is not a function

@anderskitson anderskitson added the bug Something that isn't working label May 12, 2024
@Cherry
Copy link
Contributor

Cherry commented May 12, 2024

crons expects an array, so if you change your wrangler.toml to include:

crons = ["0 * * * *"]

it should work as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that isn't working
Projects
Status: Done
Development

No branches or pull requests

3 participants