Skip to content

Using getStore outside a function only works in dev, not in production #175

Open
@rhtenhove

Description

@rhtenhove

Describe the bug

When using for example:

const blobStore = getStore("foo");

Outside a function, netlify dev is fine with it and will store and retrieve stuff as expected. However when using this in production (or a deploy preview), the following error is thrown.

{
  "errorType": "MissingBlobsEnvironmentError",
  "errorMessage": "The environment has not been configured to use Netlify Blobs. To use it manually, supply the following properties when creating a store: siteID, token",
  "trace": [
    "MissingBlobsEnvironmentError: The environment has not been configured to use Netlify Blobs. To use it manually, supply the following properties when creating a store: siteID, token",
    "    at getClientOptions (file:///var/task/node_modules/@netlify/blobs/dist/chunk-SGXOM2EY.js:298:11)",
    "    at getStore (file:///var/task/node_modules/@netlify/blobs/dist/main.js:294:27)",
    "    at file:///var/task/netlify/functions/my-cool-function.mjs:156:17",
    "    at ModuleJob.run (node:internal/modules/esm/module_job:222:25)",
    "    at async ModuleLoader.import (node:internal/modules/esm/loader:323:24)",
    "    at async _tryAwaitImport (file:///var/runtime/index.mjs:1008:16)",
    "    at async _tryRequire (file:///var/runtime/index.mjs:1057:86)",
    "    at async _loadUserApp (file:///var/runtime/index.mjs:1081:16)",
    "    at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1119:21)",
    "    at async start (file:///var/runtime/index.mjs:1282:23)"
  ]
}

To fix this, getStore needs to happen within a function called by a request.

Configuration

 System:
    OS: Linux 5.15 Ubuntu 23.10 23.10 (Mantic Minotaur)
    CPU: (20) x64 13th Gen Intel(R) Core(TM) i7-13700H
    Memory: 3.70 GB / 7.62 GB
    Container: Yes
    Shell: 3.6.1 - /usr/bin/fish
  Binaries:
    Node: 20.13.1 - /usr/local/bin/node
    npm: 10.5.2 - /usr/local/bin/npm

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugcode to address defects in shipped code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions