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

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

Open
rhtenhove opened this issue May 23, 2024 · 2 comments
Open
Labels
type: bug code to address defects in shipped code

Comments

@rhtenhove
Copy link

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
@rhtenhove rhtenhove added the type: bug code to address defects in shipped code label May 23, 2024
@hrishikesh-k
Copy link
Contributor

For internal tracking, this was first reported: https://linear.app/netlify/issue/FRP-985/ and has been fixed as of: https://linear.app/netlify/issue/FRP-959/.

The only difference is that, there getStore was being called during build time and here, based on the stack trace, this looks to be happening within a Function. I don't think the fix was for that part.

What's the use-case here? Any particular reason to call getStore outside of the default export?

@hrishikesh-k
Copy link
Contributor

I came here due to the report: https://answers.netlify.com/t/107958/11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug code to address defects in shipped code
Projects
None yet
Development

No branches or pull requests

2 participants