https://discord.cloudflare.com logo
Join Discord
Powered by
# workers-discussions
  • d

    DemosJarco

    03/10/2023, 7:18 PM
  • s

    Skye

    03/10/2023, 7:19 PM
    I can't repro 🤔
  • s

    Skye

    03/10/2023, 7:19 PM
    Admittedly, I'm using vitest - but I don't imagine it makes any difference
  • s

    Skye

    03/10/2023, 7:19 PM
    A number of wrangler's tests do use it themselves too - if it was an issue for everyone, it would have been noticed long ago
  • s

    Skye

    03/10/2023, 7:19 PM
    If you can make a minimal reproducible example, I'll happily try it out
  • d

    DemosJarco

    03/10/2023, 7:20 PM
    If I make the worker run local, it works just fine. But this one runs with
    local: false
    and is the one that hangs
  • d

    DemosJarco

    03/10/2023, 7:21 PM
    All my runs on this project are through github actions and it's a public repo so you should be able to see it all too
  • d

    DemosJarco

    03/10/2023, 7:24 PM
    That's the only difference between my testing code that works in a different project, and this one
  • d

    DemosJarco

    03/10/2023, 7:26 PM
    Yup, that's the issue. The moment I make
    local: true
    the test exits instantly
  • d

    DemosJarco

    03/10/2023, 7:26 PM
    The
    Copy code
    ts
    worker = await unstable_dev('src/index.ts', { local: false, experimental: { disableExperimentalWarning: true } });
    vs
    Copy code
    ts
    worker = await unstable_dev('src/index.ts', { local: true, experimental: { forceLocal: true, disableExperimentalWarning: true } });
  • d

    dave

    03/10/2023, 7:29 PM
    if I want to make my own
    JavaScriptRewriter
    , is this the proper way of fetching plaintext?
    Copy code
    typescript
    fetch('https://example.com/x.js',
        {
          method: 'GET',
          headers: {
            'Accept-Encoding': 'identity'
          }
        }
      );
  • s

    Skye

    03/10/2023, 7:33 PM
    Oh, interesting - definitely make an issue for that
  • s

    Skye

    03/10/2023, 7:34 PM
    You could also try experimental local to run it in a more similar environment to production than regular local can provide
  • j

    johtso

    03/10/2023, 9:02 PM
    when using ES module workers, is there some way I can monkey patch my env variables into a global process.env?
  • k

    kian

    03/10/2023, 9:04 PM
    You could throw them on globalThis but it's really not recommended
  • j

    johtso

    03/10/2023, 10:15 PM
    @kian ah amazing, I'll give that a try. I'm trying to use a library that's written to run in node, and I want to see if I can coax it into working. obviously passing an API_KEY all the way into its depths is going to be a struggle
  • k

    kian

    03/10/2023, 10:16 PM
    Is API_KEY a secret or in
    [vars]
    ?
  • j

    johtso

    03/10/2023, 10:18 PM
    I've just chucked it in vars for development, not sure of the distinction
  • j

    johtso

    03/10/2023, 10:19 PM
    is a secret something set in the dashboard?
  • j

    johtso

    03/10/2023, 10:20 PM
    @kian I should be using
    .dev.vars
    instead of putting it in
    wrangler.dev.toml
    ?
  • j

    johtso

    03/10/2023, 10:21 PM
    they're both shoved into
    env
    right?
  • j

    johtso

    03/10/2023, 11:28 PM
    are there any particular reasons why this isn't recommended? what if I need to write code that has to run in both a node environment (that I don't control) with secrets provided through process.env.. and also in my remix app in my worker?
  • h

    HardAtWork

    03/10/2023, 11:30 PM
    It isn’t recommended because CF can sometimes switch environments without fully rebooting your Worker. If you are always running from the env object, that won’t be an issue. If you are pulling from the global scope, you might suddenly be trying to reach a binding that no longer exists
  • h

    HardAtWork

    03/10/2023, 11:30 PM
    This is why the env object exists in the module syntax, rather than globals in the service Worker syntax
  • j

    johtso

    03/10/2023, 11:30 PM
    but if I copy the variables from the env object to
    globalThis
    in my fetch function that should be fine right?
  • j

    johtso

    03/10/2023, 11:31 PM
    a request can't move environment mid request can it?
  • j

    johtso

    03/10/2023, 11:32 PM
    I'm specifically trying to work with the newly announced https://defer.run
  • j

    johtso

    03/10/2023, 11:32 PM
    it does some magic where you have background task functions that are wrapped to proxy to their service through an API
  • h

    HardAtWork

    03/10/2023, 11:32 PM
    No, but a Worker may be processing multiple requests at once, and may be reused multiple times
  • j

    johtso

    03/10/2023, 11:34 PM
    hmm, also the library I'm using tries to get the environment variable at import time so maybe I'm screwed
1...233423352336...2509Latest