Cannot write to blob from js function

https://subtle-crepe-f83d81.netlify.app/

i am able to write to the blob from the command line
netlify blobs:set clouds file1.txt 11111111111111

but when i try a function (which is copied from the example in the docs) i get this error: accept: ‘text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.7’,
‘accept-encoding’: ‘br’,
‘accept-language’: ‘en-US,en;q=0.9’,
‘cache-control’: ‘max-age=0’,
‘cdn-loop’: ‘netlify’,
dnt: ‘1’,
host: ‘subtle-crepe-f83d81.netlify.app’,
priority: ‘u=0, i’,
‘sec-ch-ua’: ‘“Not/A)Brand”;v=“8”, “Chromium”;v=“126”, “Google Chrome”;v=“126”’,
‘sec-ch-ua-mobile’: ‘?0’,
‘sec-ch-ua-platform’: ‘“Windows”’,
‘sec-fetch-dest’: ‘document’,
‘sec-fetch-mode’: ‘navigate’,
‘sec-fetch-site’: ‘none’,
‘sec-fetch-user’: ‘?1’,
‘upgrade-insecure-requests’: ‘1’,
‘user-agent’: ‘Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36’,
‘x-country’: ‘US’,
‘x-forwarded-for’: ‘2601:1c0:847e:6b50:bcb3:1655:9ba3:62cc’,
‘x-forwarded-proto’: ‘https’,
‘x-language’: ‘en-US’,
‘x-nf-account-id’: ‘667d92ffca7a2b26fa962351’,
‘x-nf-client-connection-ip’: ‘2601:1c0:847e:6b50:bcb3:1655:9ba3:62cc’,
‘x-nf-deploy-id’: ‘6682f384a469ba6fd3ab61f9’,
‘x-nf-geo’: ‘eyJjaXR5IjoiQ29ydmFsbGlzIiwiY291bnRyeSI6eyJjb2RlIjoiVVMiLCJuYW1lIjoiVW5pdGVkIFN0YXRlcyJ9LCJzdWJkaXZpc2lvbiI6eyJjb2RlIjoiT1IiLCJuYW1lIjoiT3JlZ29uIn0sInRpbWV6b25lIjoiQW1lcmljYS9Mb3NfQW5nZWxlcyIsImxhdGl0dWRlIjo0NC41OTI4LCJsb25naXR1ZGUiOi0xMjMuMjc0Nn0=’,
‘x-nf-request-id’: ‘01J1QRMNXEYZGXC9F2G4377KXB’,
‘x-nf-site-id’: ‘fb79a99c-2ed2-4f6b-839f-bf41b9b0b12c’
},
multiValueHeaders: {
Accept: [
‘text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.7’
],
‘Accept-Encoding’: [ ‘br’ ],
‘Accept-Language’: [ ‘en-US,en;q=0.9’ ],
‘Cache-Control’: [ ‘max-age=0’ ],
‘Cdn-Loop’: [ ‘netlify’ ],
Dnt: [ ‘1’ ],
Priority: [ ‘u=0, i’ ],
‘Sec-Ch-Ua’: [
‘“Not/A)Brand”;v=“8”, “Chromium”;v=“126”, “Google Chrome”;v=“126”’
],
‘Sec-Ch-Ua-Mobile’: [ ‘?0’ ],
‘Sec-Ch-Ua-Platform’: [ ‘“Windows”’ ],
‘Sec-Fetch-Dest’: [ ‘document’ ],
‘Sec-Fetch-Mode’: [ ‘navigate’ ],
‘Sec-Fetch-Site’: [ ‘none’ ],
‘Sec-Fetch-User’: [ ‘?1’ ],
‘Upgrade-Insecure-Requests’: [ ‘1’ ],
‘User-Agent’: [
‘Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36’
],
‘X-Country’: [ ‘US’ ],
‘X-Forwarded-For’: [ ‘2601:1c0:847e:6b50:bcb3:1655:9ba3:62cc’ ],
‘X-Forwarded-Proto’: [ ‘https’ ],
‘X-Language’: [ ‘en-US’ ],
‘X-Nf-Account-Id’: [ ‘667d92ffca7a2b26fa962351’ ],
‘X-Nf-Client-Connection-Ip’: [ ‘2601:1c0:847e:6b50:bcb3:1655:9ba3:62cc’ ],
‘X-Nf-Deploy-Id’: [ ‘6682f384a469ba6fd3ab61f9’ ],
‘X-Nf-Geo’: [
‘eyJjaXR5IjoiQ29ydmFsbGlzIiwiY291bnRyeSI6eyJjb2RlIjoiVVMiLCJuYW1lIjoiVW5pdGVkIFN0YXRlcyJ9LCJzdWJkaXZpc2lvbiI6eyJjb2RlIjoiT1IiLCJuYW1lIjoiT3JlZ29uIn0sInRpbWV6b25lIjoiQW1lcmljYS9Mb3NfQW5nZWxlcyIsImxhdGl0dWRlIjo0NC41OTI4LCJsb25naXR1ZGUiOi0xMjMuMjc0Nn0=’
],
‘X-Nf-Request-Id’: [ ‘01J1QRMNXEYZGXC9F2G4377KXB’ ],
‘X-Nf-Site-Id’: [ ‘fb79a99c-2ed2-4f6b-839f-bf41b9b0b12c’ ],
host: [ ‘subtle-crepe-f83d81.netlify.app’ ]
},
queryStringParameters: {},
multiValueQueryStringParameters: {},
body: ‘’,
isBase64Encoded: true,
blobs: ‘eyJwcmltYXJ5X3JlZ2lvbiI6InVzLWVhc3QtMiIsInVybCI6Imh0dHBzOi8vZWRnZS5uZXRsaWZ5YmxvYnMuY29tIiwidXJsX3VuY2FjaGVkIjoiaHR0cHM6Ly9lZGdlLXVuY2FjaGVkLm5ldGxpZnlibG9icy5jb20iLCJ0b2tlbiI6ImV5SmhiR2NpT2lKSVV6STFOaUlzSW5SNWNDSTZJa3BYVkNKOS5leUpwYzNNaU9pSnVaWFJzYVdaNUlpd2ljM1ZpSWpvaU1DSXNJbVY0Y0NJNk1UY3hPVGcxT1RFMU5Td2lhV0YwSWpveE56RTVPRFU0TWpVMUxDSnphWFJsWDJsa0lqb2labUkzT1dFNU9XTXRNbVZrTWkwMFpqWmlMVGd6T1dZdFltWTBNV0k1WWpCaU1USmpJbjAuT3R4Q1FuVWV6UlpMbnFLZjJOX19ad3RNTGQ3V18tSEc4X1RYTkFNUFdhVSJ9’,
flags: {
serverless_functions_fix_empty_body: true,
serverless_functions_next_otel: false,
serverless_functions_nextjs_durable_cache: false,
serverless_functions_request_interceptor: false,
serverless_functions_request_interceptor_v2: true,
serverless_functions_test_flag: true,
serverless_functions_wait_event_loop: true
},
invocationMetadata: { accountTier: ‘Starter’ }
}Jul 1, 11:24:15 AM: f8e56cc6 ERROR Missing siteID or token in environment variables

my function:require(‘dotenv’).config();
const { getStore } = require(‘@netlify/blobs’);

exports.handler = function(event, context, callback) {
console.log(‘Event:’, event);

// Fetch environment variables
const siteID = process.env.NETLIFY_SITE_ID;
const token = process.env.NETLIFY_API_TOKEN;

// Ensure environment variables are set
if (!siteID || !token) {
console.error(‘Missing siteID or token in environment variables’);
return callback(null, {
statusCode: 500,
body: JSON.stringify({ error: ‘Missing siteID or token in environment variables’ })
});
}

// Get the construction store and set a value
var construction = getStore(‘clouds-001’, { siteID: siteID, token: token });
construction.set(‘file3.txt’, ‘For general carpentry’)
.then(function() {
callback(null, {
statusCode: 200,
body: ‘Nail blobs set for Construction and Beauty stores’
});
})
.catch(function(error) {
console.error(‘Error setting blobs:’, error);
callback(null, {
statusCode: 500,
body: JSON.stringify({ error: error.message })
});
});
};

Some additonal information. I wrote a series of functions, first checked the keys in my env file, then checked for the existence of a store – which existed. but when i try to write to the store i get the error that the enviornment is not set up for blobs
Jul 1, 03:52:57 PM: INIT_START Runtime Version: nodejs:18.v30 Runtime Version ARN: arn:aws:lambda:us-east-2::runtime:f89c264158db39a1cfcbb5f9b3741413df1cfce4d550c9a475a67d923e19e2f4Jul 1, 03:52:58 PM: b814989f INFO NETLIFY_SITE_ID: fb79a99c-2ed2-4f6b-839f-bf41b9b0b12cJul 1, 03:52:58 PM: b814989f INFO NETLIFY_AUTH_TOKEN: nfp_mEsX6Hi4xxMQreew7NMgW6x84CrpsYbk9d8cJul 1, 03:52:58 PM: b814989f INFO Stores: [ ‘clouds-001’, ‘clouds’ ]Jul 1, 03:52:58 PM: b814989f INFO Store “clouds-001” exists: trueJul 1, 03:52:58 PM: b814989f ERROR Error setting dummy record: 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 (/var/task/node_modules/@netlify/blobs/dist/main.cjs:340:11)
at getStore (/var/task/node_modules/@netlify/blobs/dist/main.cjs:623:27)
at exports.handler (/var/task/netlify/functions/write-to-store.js:37:23)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)Jul 1, 03:52:58 PM: b814989f Duration: 274.56 ms Memory Usage: 96 MB Init Duration: 249.16 ms Jul 1, 03:52:58 PM: e11f9f19 INFO NETLIFY_SITE_ID: fb79a99c-2ed2-4f6b-839f-bf41b9b0b12cJul 1, 03:52:58 PM: e11f9f19 INFO NETLIFY_AUTH_TOKEN: nfp_mEsX6Hi4xxMQreew7NMgW6x84CrpsYbk9d8cJul 1, 03:52:58 PM: e11f9f19 INFO Stores: [ ‘clouds-001’, ‘clouds’ ]Jul 1, 03:52:58 PM: e11f9f19 INFO Store “clouds-001” exists: trueJul 1, 03:52:58 PM: e11f9f19 ERROR Error setting dummy record: 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 (/var/task/node_modules/@netlify/blobs/dist/main.cjs:340:11)
at getStore (/var/task/node_modules/@netlify/blobs/dist/main.cjs:623:27)
at exports.handler (/var/task/netlify/functions/write-to-store.js:37:23)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)Jul 1, 03:52:58 PM: e11f9f19 Duration: 100.73 ms Memory Usage: 106 MB
here is the offending file:
const { getStore, listStores } = require(‘@netlify/blobs’);
require(‘dotenv’).config(); // Load environment variables from .env file

exports.handler = async function(event, context) {
// Fetch and log environment variables
const siteID = process.env.NETLIFY_SITE_ID;
const authToken = process.env.NETLIFY_AUTH_TOKEN;

console.log(‘NETLIFY_SITE_ID:’, siteID);
console.log(‘NETLIFY_AUTH_TOKEN:’, authToken);

// Check if environment variables are set
if (!siteID || !authToken) {
return {
statusCode: 500,
body: JSON.stringify({ error: ‘Missing NETLIFY_SITE_ID or NETLIFY_AUTH_TOKEN in environment variables’ }),
};
}

try {
// List all stores
const { stores } = await listStores({
siteID: siteID,
token: authToken
});

// Check if a specific store exists
const storeName = 'clouds-001';
const storeExists = stores.includes(storeName);

console.log('Stores:', stores);
console.log(`Store "${storeName}" exists:`, storeExists);

// Write a dummy record to the store if it exists
if (storeExists) {
  try {
    const store = getStore(storeName, {
      siteID: siteID,
      token: authToken
    });

    const key = 'dummy-key';
    const value = 'dummy-value';

    await store.set(key, value);
    console.log(`Dummy record set in store: ${storeName} with key: ${key}`);

    return {
      statusCode: 200,
      body: JSON.stringify({ message: `Dummy record set in store: ${storeName} with key: ${key}` }),
    };
  } catch (error) {
    console.error('Error setting dummy record:', error);
    return {
      statusCode: 500,
      body: JSON.stringify({ error: 'Error setting dummy record' }),
    };
  }
} else {
  return {
    statusCode: 404,
    body: JSON.stringify({ error: `Store ${storeName} does not exist` }),
  };
}

} catch (error) {
console.error(‘Error listing stores:’, error);
return {
statusCode: 500,
body: JSON.stringify({ error: error.message }),
};
}
};

i converted the js file to ver 2 and re ran the test, basically same error. you can see that the code can retrieve the store names from the project, but cannot write to them:
Jul 1, 03:59:25 PM: INIT_START Runtime Version: nodejs:18.v30 Runtime Version ARN: arn:aws:lambda:us-east-2::runtime:f89c264158db39a1cfcbb5f9b3741413df1cfce4d550c9a475a67d923e19e2f4Jul 1, 03:59:25 PM: bcdf31cb INFO NETLIFY_SITE_ID: fb79a99c-2ed2-4f6b-839f-bf41b9b0b12cJul 1, 03:59:25 PM: bcdf31cb INFO NETLIFY_AUTH_TOKEN: nfp_mEsX6Hi4xxMQreew7NMgW6x84CrpsYbk9d8cJul 1, 03:59:25 PM: bcdf31cb INFO Stores: [ ‘clouds-001’, ‘clouds’ ]Jul 1, 03:59:25 PM: bcdf31cb INFO Store “clouds-001” exists: trueJul 1, 03:59:25 PM: bcdf31cb ERROR Error setting dummy record: 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 (/var/task/node_modules/@netlify/blobs/dist/main.cjs:340:11)
at getStore (/var/task/node_modules/@netlify/blobs/dist/main.cjs:623:27)
at Runtime.handler (/var/task/netlify/functions/write-to-store.js:48:49)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)Jul 1, 03:59:25 PM: bcdf31cb Duration: 301.40 ms Memory Usage: 97 MB Init Duration: 249.17 ms

your function is failing because the required environment variables (NETLIFY_SITE_ID and NETLIFY_API_TOKEN) are not set. Here’s how you can resolve this issue:

Step-by-Step Solution

  1. Set Environment Variables in Netlify:
  • Go to your Netlify dashboard.
  • Select your site.
  • Navigate to Site settings.
  • Under Build & deploy, find the Environment section.
  • Add the environment variables NETLIFY_SITE_ID and NETLIFY_API_TOKEN with their respective values.

Example:

  • NETLIFY_SITE_ID: your-site-id
  • NETLIFY_API_TOKEN: your-api-token

Example Function with Improved Error Handling

To enhance error handling and ensure that environment variables are correctly set, you can modify your function as follows:

javascript

Copy code

require('dotenv').config();
const { getStore } = require('@netlify/blobs');

exports.handler = async function(event, context) {
    console.log('Event:', event);

    // Fetch environment variables
    const siteID = process.env.NETLIFY_SITE_ID;
    const token = process.env.NETLIFY_API_TOKEN;

    // Ensure environment variables are set
    if (!siteID || !token) {
        console.error('Missing siteID or token in environment variables');
        return {
            statusCode: 500,
            body: JSON.stringify({ error: 'Missing siteID or token in environment variables' })
        };
    }

    try {
        // Get the construction store and set a value
        const construction = getStore('clouds-001', { siteID: siteID, token: token });
        await construction.set('file3.txt', 'For general carpentry');
        return {
            statusCode: 200,
            body: 'Nail blobs set for Construction and Beauty stores'
        };
    } catch (error) {
        console.error('Error setting blobs:', error);
        return {
            statusCode: 500,
            body: JSON.stringify({ error: error.message })
        };
    }
};

Additional Tips

  • Ensure .env File is Ignored: Make sure your .env file is in your .gitignore file to prevent it from being committed to version control.
  • Check for Spelling Errors: Double-check that the environment variable names in your Netlify settings exactly match those used in your code (NETLIFY_SITE_ID and NETLIFY_API_TOKEN).

By setting the environment variables correctly and ensuring your function has appropriate error handling, you should be able to resolve the issues and successfully use the netlify/blobs package in your Netlify functions.

let me try again. this morning i changed the function to pass the literal text values of the 2 keys instead of relying on env variables. i still get the same error. note that the function is able to return the correct list of stores and confirm that ‘could-001’ exists
STILL i get the ‘environment’ error when i try to read or write a record: is there any way to 'configure the environment to use netfliy blobs ’ ???

import { getStore, listStores } from ‘@netlify/blobs’;
import { config } from ‘dotenv’;

// Load environment variables from .env file
config();

export async function handler(event, context) {
// Fetch and log environment variables
const siteID = “fb79a99c-2ed2-4f6b-839f-bf41b9b0b12c” //process.env.NETLIFY_SITE_ID;
const authToken = “nfp_mEsX6Hi4xxMQreew7NMgW6x84CrpsYbk9d8c” //process.env.NETLIFY_AUTH_TOKEN;

console.log(‘NETLIFY_SITE_ID:’, siteID);
console.log(‘NETLIFY_AUTH_TOKEN:’, authToken);

// Check if environment variables are set
if (!siteID || !authToken) {
return {
statusCode: 500,
body: JSON.stringify({ error: ‘Missing NETLIFY_SITE_ID or NETLIFY_AUTH_TOKEN in environment variables’ }),
};
}

try {
// List all stores
const { stores } = await listStores({
siteID: siteID,
token: authToken
});

// Check if a specific store exists
const storeName = ‘clouds-001’;
const storeExists = stores.includes(storeName);

console.log(‘Stores:’, stores);
console.log(Store "${storeName}" exists:, storeExists);

// Write a dummy record to the store if it exists
if (storeExists) {
try {
const store = getStore(storeName, {
siteID: siteID,
token: authToken
});

const key = ‘dummy-key’;
const value = ‘dummy-value’;

await store.set(key, value);
console.log(Dummy record set in store: ${storeName} with key: ${key});

return {
statusCode: 200,
body: JSON.stringify({ message: Dummy record set in store: ${storeName} with key: ${key} }),
};
} catch (error) {
console.error(‘Error setting dummy record:’, error);
return {
statusCode: 500,
body: JSON.stringify({ error: ‘Error setting dummy record’ }),
};
}
} else {
return {
statusCode: 404,
body: JSON.stringify({ error: Store ${storeName} does not exist }),
};
}
} catch (error) {
console.error(‘Error listing stores:’, error);
return {
statusCode: 500,
body: JSON.stringify({ error: error.message }),
};
}
}

Jul 2, 07:03:40 AM: INIT_START Runtime Version: nodejs:18.v30 Runtime Version ARN: arn:aws:lambda:us-east-2::runtime:f89c264158db39a1cfcbb5f9b3741413df1cfce4d550c9a475a67d923e19e2f4
Jul 2, 07:03:41 AM: d2c98474 INFO NETLIFY_SITE_ID: fb79a99c-2ed2-4f6b-839f-bf41b9b0b12c
Jul 2, 07:03:41 AM: d2c98474 INFO NETLIFY_AUTH_TOKEN: nfp_mEsX6Hi4xxMQreew7NMgW6x84CrpsYbk9d8c
Jul 2, 07:03:41 AM: d2c98474 INFO Stores: [ ‘clouds-001’, ‘clouds’ ]
Jul 2, 07:03:41 AM: d2c98474 INFO Store “clouds-001” exists: true
Jul 2, 07:03:41 AM: d2c98474 ERROR Error setting dummy record: 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 (/var/task/node_modules/@netlify/blobs/dist/main.cjs:340:11)
at getStore (/var/task/node_modules/@netlify/blobs/dist/main.cjs:623:27)
at Runtime.handler (/var/task/netlify/functions/write-to-store.js:48:49)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Jul 2, 07:03:41 AM: d2c98474 Duration: 298.43 ms Memory Usage: 96 MB Init Duration: 246.66 ms

import { getStore, listStores } from ‘@netlify/blobs’;
import { config } from ‘dotenv’;

// Load environment variables from .env file
config();

export async function handler(event, context) {
// Fetch and log environment variables
const siteID = “fb79a99c-2ed2-4f6b-839f-bf41b9b0b12c” //process.env.NETLIFY_SITE_ID;
const authToken = “nfp_mEsX6Hi4xxMQreew7NMgW6x84CrpsYbk9d8c” //process.env.NETLIFY_AUTH_TOKEN;

console.log(‘NETLIFY_SITE_ID:’, siteID);
console.log(‘NETLIFY_AUTH_TOKEN:’, authToken);

// Check if environment variables are set
if (!siteID || !authToken) {
return {
statusCode: 500,
body: JSON.stringify({ error: ‘Missing NETLIFY_SITE_ID or NETLIFY_AUTH_TOKEN in environment variables’ }),
};
}

try {
// List all stores
const { stores } = await listStores({
siteID: siteID,
token: authToken
});

// Check if a specific store exists
const storeName = ‘clouds-001’;
const storeExists = stores.includes(storeName);

console.log(‘Stores:’, stores);
console.log(Store "${storeName}" exists:, storeExists);

// Write a dummy record to the store if it exists
if (storeExists) {
try {
const store = getStore(storeName, {
siteID: siteID,
token: authToken
});

const key = ‘dummy-key’;
const value = ‘dummy-value’;

await store.set(key, value);
console.log(Dummy record set in store: ${storeName} with key: ${key});

return {
statusCode: 200,
body: JSON.stringify({ message: Dummy record set in store: ${storeName} with key: ${key} }),
};
} catch (error) {
console.error(‘Error setting dummy record:’, error);
return {
statusCode: 500,
body: JSON.stringify({ error: ‘Error setting dummy record’ }),
};
}
} else {
return {
statusCode: 404,
body: JSON.stringify({ error: Store ${storeName} does not exist }),
};
}
} catch (error) {
console.error(‘Error listing stores:’, error);
return {
statusCode: 500,
body: JSON.stringify({ error: error.message }),
};
}
}

further investigation; I found this sample code in your docs and converted it from typescript to javascript:import { getStore } from “@netlify/blobs”;

import { Context } from “@netlify/functions”;

export default async function handler(req, context) {
const store = getStore({ name: “animals”, consistency: “strong” });

await store.set(“dog”, “:dog:”);

// This is a strongly-consistent read.
const dog = await store.get(“dog”);

return new Response(dog);

when i do netlify dev, it runs successfully on my local environment. when i deploy to production it throws this error:
Jul 2, 07:24:47 AM: 2024-07-02T14:24:47.995Z undefined ERROR Uncaught Exception {“errorType”:“Runtime.ImportModuleError”,“errorMessage”:“Error: Cannot find module ‘@netlify/functions’\nRequire stack:\n- /var/task/netlify/functions/insert-dog-test.cjs”,“stack”:[“Runtime.ImportModuleError: Error: Cannot find module ‘@netlify/functions’”,“Require stack:”,“- /var/task/netlify/functions/insert-dog-test.cjs”," at _loadUserApp (file:///var/runtime/index.mjs:1087:17)“,” at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1119:21)“,” at async start (file:///var/runtime/index.mjs:1282:23)“,” at async file:///var/runtime/index.mjs:1288:1"]}
Jul 2, 07:24:48 AM: 2024-07-02T14:24:48.009Z undefined ERROR Unhandled Promise Rejection {“errorType”:“Runtime.UnhandledPromiseRejection”,“errorMessage”:“Error: Cannot find module ‘@netlify/functions’\nRequire stack:\n- /var/task/netlify/functions/insert-dog-test.cjs”,“reason”:{“errorType”:“Error”,“errorMessage”:“Cannot find module ‘@netlify/functions’\nRequire stack:\n- /var/task/netlify/functions/insert-dog-test.cjs”,“code”:“MODULE_NOT_FOUND”,“requireStack”:[“/var/task/netlify/functions/insert-dog-test.cjs”],“stack”:[“Error: Cannot find module ‘@netlify/functions’”,“Require stack:”,“- /var/task/netlify/functions/insert-dog-test.cjs”," at Module._resolveFilename (node:internal/modules/cjs/loader:1140:15)“,” at Module._load (node:internal/modules/cjs/loader:981:27)“,” at Module.require (node:internal/modules/cjs/loader:1231:19)“,” at require (node:internal/modules/helpers:177:18)“,” at Object. (/var/task/netlify/functions/insert-dog-test.cjs:26:24)“,” at Module._compile (node:internal/modules/cjs/loader:1364:14)“,” at Module._extensions…js (node:internal/modules/cjs/loader:1422:10)“,” at Module.load (node:internal/modules/cjs/loader:1203:32)“,” at Module._load (node:internal/modules/cjs/loader:1019:12)“,” at ModuleWrap. (node:internal/modules/esm/translators:203:29)“]},“promise”:{},“stack”:[“Runtime.UnhandledPromiseRejection: Error: Cannot find module ‘@netlify/functions’”,“Require stack:”,”- /var/task/netlify/functions/insert-dog-test.cjs"," at process. (file:///var/runtime/index.mjs:1276:17)“,” at process.emit (node:events:517:28)“,” at emit (node:internal/process/promises:149:20)“,” at processPromiseRejections (node:internal/process/promises:283:27)“,” at process.processTicksAndRejections (node:internal/process/task_queues:96:32)"]}
Jul 2, 07:24:48 AM: INIT_REPORT Init Duration: 425.15 ms Phase: invoke Status: error Error Type: Runtime.ImportModuleError
Jul 2, 07:24:48 AM: Unknown application error occurred
Runtime.ImportModuleError
Jul 2, 07:24:48 AM: 20da6b03 Duration: 589.94 ms Memory Usage: 30 MB

Jul 2, 07:24:47 AM: 2024-07-02T14:24:47.995Z undefined ERROR Uncaught Exception {“errorType”:“Runtime.ImportModuleError”,“errorMessage”:“Error: Cannot find module ‘@netlify/functions’\nRequire stack:\n- /var/task/netlify/functions/insert-dog-test.cjs”,“stack”:[“Runtime.ImportModuleError: Error: Cannot find module ‘@netlify/functions’”,“Require stack:”,“- /var/task/netlify/functions/insert-dog-test.cjs”," at _loadUserApp (file:///var/runtime/index.mjs:1087:17)“,” at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1119:21)“,” at async start (file:///var/runtime/index.mjs:1282:23)“,” at async file:///var/runtime/index.mjs:1288:1"]}
Jul 2, 07:24:48 AM: 2024-07-02T14:24:48.009Z undefined ERROR Unhandled Promise Rejection {“errorType”:“Runtime.UnhandledPromiseRejection”,“errorMessage”:“Error: Cannot find module ‘@netlify/functions’\nRequire stack:\n- /var/task/netlify/functions/insert-dog-test.cjs”,“reason”:{“errorType”:“Error”,“errorMessage”:“Cannot find module ‘@netlify/functions’\nRequire stack:\n- /var/task/netlify/functions/insert-dog-test.cjs”,“code”:“MODULE_NOT_FOUND”,“requireStack”:[“/var/task/netlify/functions/insert-dog-test.cjs”],“stack”:[“Error: Cannot find module ‘@netlify/functions’”,“Require stack:”,“- /var/task/netlify/functions/insert-dog-test.cjs”," at Module._resolveFilename (node:internal/modules/cjs/loader:1140:15)“,” at Module._load (node:internal/modules/cjs/loader:981:27)“,” at Module.require (node:internal/modules/cjs/loader:1231:19)“,” at require (node:internal/modules/helpers:177:18)“,” at Object. (/var/task/netlify/functions/insert-dog-test.cjs:26:24)“,” at Module._compile (node:internal/modules/cjs/loader:1364:14)“,” at Module._extensions…js (node:internal/modules/cjs/loader:1422:10)“,” at Module.load (node:internal/modules/cjs/loader:1203:32)“,” at Module._load (node:internal/modules/cjs/loader:1019:12)“,” at ModuleWrap. (node:internal/modules/esm/translators:203:29)“]},“promise”:{},“stack”:[“Runtime.UnhandledPromiseRejection: Error: Cannot find module ‘@netlify/functions’”,“Require stack:”,”- /var/task/netlify/functions/insert-dog-test.cjs"," at process. (file:///var/runtime/index.mjs:1276:17)“,” at process.emit (node:events:517:28)“,” at emit (node:internal/process/promises:149:20)“,” at processPromiseRejections (node:internal/process/promises:283:27)“,” at process.processTicksAndRejections (node:internal/process/task_queues:96:32)"]}
Jul 2, 07:24:48 AM: INIT_REPORT Init Duration: 425.15 ms Phase: invoke Status: error Error Type: Runtime.ImportModuleError
Jul 2, 07:24:48 AM: Unknown application error occurred
Runtime.ImportModuleError
Jul 2, 07:24:48 AM: 20da6b03 Duration: 589.94 ms Memory Usage: 30 MB

Jul 2, 07:33:39 AM: INIT_START Runtime Version: nodejs:18.v30 Runtime Version ARN: arn:aws:lambda:us-east-2::runtime:f89c264158db39a1cfcbb5f9b3741413df1cfce4d550c9a475a67d923e19e2f4Jul 2, 07:33:39 AM: 2024-07-02T14:33:39.545Z undefined ERROR Uncaught Exception {“errorType”:“Runtime.ImportModuleError”,“errorMessage”:“Error: Cannot find module ‘@netlify/functions’\nRequire stack:\n- /var/task/netlify/functions/insert-dog-test.cjs”,“stack”:[“Runtime.ImportModuleError: Error: Cannot find module ‘@netlify/functions’”,“Require stack:”,“- /var/task/netlify/functions/insert-dog-test.cjs”," at _loadUserApp (file:///var/runtime/index.mjs:1087:17)“,” at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1119:21)“,” at async start (file:///var/runtime/index.mjs:1282:23)“,” at async file:///var/runtime/index.mjs:1288:1"]}Jul 2, 07:33:39 AM: 2024-07-02T14:33:39.552Z undefined ERROR Unhandled Promise Rejection {“errorType”:“Runtime.UnhandledPromiseRejection”,“errorMessage”:“Error: Cannot find module ‘@netlify/functions’\nRequire stack:\n- /var/task/netlify/functions/insert-dog-test.cjs”,“reason”:{“errorType”:“Error”,“errorMessage”:“Cannot find module ‘@netlify/functions’\nRequire stack:\n- /var/task/netlify/functions/insert-dog-test.cjs”,“code”:“MODULE_NOT_FOUND”,“requireStack”:[“/var/task/netlify/functions/insert-dog-test.cjs”],“stack”:[“Error: Cannot find module ‘@netlify/functions’”,“Require stack:”,“- /var/task/netlify/functions/insert-dog-test.cjs”," at Module._resolveFilename (node:internal/modules/cjs/loader:1140:15)“,” at Module._load (node:internal/modules/cjs/loader:981:27)“,” at Module.require (node:internal/modules/cjs/loader:1231:19)“,” at require (node:internal/modules/helpers:177:18)“,” at Object. (/var/task/netlify/functions/insert-dog-test.cjs:26:24)“,” at Module._compile (node:internal/modules/cjs/loader:1364:14)“,” at Module._extensions…js (node:internal/modules/cjs/loader:1422:10)“,” at Module.load (node:internal/modules/cjs/loader:1203:32)“,” at Module._load (node:internal/modules/cjs/loader:1019:12)“,” at ModuleWrap. (node:internal/modules/esm/translators:203:29)“]},“promise”:{},“stack”:[“Runtime.UnhandledPromiseRejection: Error: Cannot find module ‘@netlify/functions’”,“Require stack:”,”- /var/task/netlify/functions/insert-dog-test.cjs"," at process. (file:///var/runtime/index.mjs:1276:17)“,” at process.emit (node:events:517:28)“,” at emit (node:internal/process/promises:149:20)“,” at processPromiseRejections (node:internal/process/promises:283:27)“,” at process.processTicksAndRejections (node:internal/process/task_queues:96:32)“]}Jul 2, 07:33:39 AM: INIT_REPORT Init Duration: 344.10 ms Phase: init Status: error Error Type: Runtime.ImportModuleErrorJul 2, 07:33:39 AM: 2024-07-02T14:33:39.994Z undefined ERROR Uncaught Exception {“errorType”:“Runtime.ImportModuleError”,“errorMessage”:“Error: Cannot find module ‘@netlify/functions’\nRequire stack:\n- /var/task/netlify/functions/insert-dog-test.cjs”,“stack”:[“Runtime.ImportModuleError: Error: Cannot find module ‘@netlify/functions’”,“Require stack:”,”- /var/task/netlify/functions/insert-dog-test.cjs"," at _loadUserApp (file:///var/runtime/index.mjs:1087:17)“,” at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1119:21)“,” at async start (file:///var/runtime/index.mjs:1282:23)“,” at async file:///var/runtime/index.mjs:1288:1"]}Jul 2, 07:33:40 AM: 2024-07-02T14:33:40.009Z undefined ERROR Unhandled Promise Rejection {“errorType”:“Runtime.UnhandledPromiseRejection”,“errorMessage”:“Error: Cannot find module ‘@netlify/functions’\nRequire stack:\n- /var/task/netlify/functions/insert-dog-test.cjs”,“reason”:{“errorType”:“Error”,“errorMessage”:“Cannot find module ‘@netlify/functions’\nRequire stack:\n- /var/task/netlify/functions/insert-dog-test.cjs”,“code”:“MODULE_NOT_FOUND”,“requireStack”:[“/var/task/netlify/functions/insert-dog-test.cjs”],“stack”:[“Error: Cannot find module ‘@netlify/functions’”,“Require stack:”,“- /var/task/netlify/functions/insert-dog-test.cjs”," at Module._resolveFilename (node:internal/modules/cjs/loader:1140:15)“,” at Module._load (node:internal/modules/cjs/loader:981:27)“,” at Module.require (node:internal/modules/cjs/loader:1231:19)“,” at require (node:internal/modules/helpers:177:18)“,” at Object. (/var/task/netlify/functions/insert-dog-test.cjs:26:24)“,” at Module._compile (node:internal/modules/cjs/loader:1364:14)“,” at Module._extensions…js (node:internal/modules/cjs/loader:1422:10)“,” at Module.load (node:internal/modules/cjs/loader:1203:32)“,” at Module._load (node:internal/modules/cjs/loader:1019:12)“,” at ModuleWrap. (node:internal/modules/esm/translators:203:29)“]},“promise”:{},“stack”:[“Runtime.UnhandledPromiseRejection: Error: Cannot find module ‘@netlify/functions’”,“Require stack:”,”- /var/task/netlify/functions/insert-dog-test.cjs"," at process. (file:///var/runtime/index.mjs:1276:17)“,” at process.emit (node:events:517:28)“,” at emit (node:internal/process/promises:149:20)“,” at processPromiseRejections (node:internal/process/promises:283:27)“,” at process.processTicksAndRejections (node:internal/process/task_queues:96:32)"]}Jul 2, 07:33:40 AM: INIT_REPORT Init Duration: 446.25 ms Phase: invoke Status: error Error Type: Runtime.ImportModuleErrorJul 2, 07:33:40 AM: Unknown application error occurred
Runtime.ImportModuleErrorJul 2, 07:33:40 AM: 46a30115 Duration: 543.00 ms Memory Usage: 30 MB

after further experiments this seems to be working now: import { getStore } from “@netlify/blobs”;

import { Context } from “@netlify/functions”;

export default async function handler(req, context) {
const store = getStore({ name: “clouds-001”, consistency: “strong” });

await store.set(“file2.txt”, “222222222222222222222222”);

// This is a strongly-consistent read.
const filecontent = await store.get(“file2.txt”);

return new Response(filecontent);
}
no idea what the difference is from before
thanks for your help
ken tyler

i was perhaps overly optimistic. The simple function works to insert literal values, but when i turn them into parameters and attempt to invoke it from another function it goes back to the environment error:
Error calling insertFile: 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:///C:/Users/Ken/Desktop/git%20pages/thinking-tools-dev/node_modules/@netlify/blobs/dist/chunk-SGXOM2EY.js:298:11)
at getStore (file:///C:/Users/Ken/Desktop/git%20pages/thinking-tools-dev/node_modules/@netlify/blobs/dist/main.js:300:27)
at insertFile (file:///C:/Users/Ken/Desktop/git%20pages/thinking-tools-dev/netlify/functions/insertFile.mjs:4:17)
at callInsertFileWithParams (file:///C:/Users/Ken/Desktop/git%20pages/thinking-tools-dev/netlify/functions/insert-file-test.mjs:9:28)
at file:///C:/Users/Ken/Desktop/git%20pages/thinking-tools-dev/netlify/functions/insert-file-test.mjs:18:1
at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
at async loadESM (node:internal/process/esm_loader:28:7)
at async handleMainPromise (node:internal/modules/run_main:113:12)
PS C:\Users\Ken\Desktop\git pages\thinking-tools-dev\netlify\functions>

import insertFile from ‘./insertFile.mjs’;

async function callInsertFileWithParams() {
const storename = “clouds-001”;
const keyname = “file5.txt”;
const valuetext = “455555442222”;

try {
const response = await insertFile(storename, keyname, valuetext);
const text = await response.text();
console.log(‘Response from insertFile:’, text);
} catch (error) {
console.error(‘Error calling insertFile:’, error);
}
}

// Call the wrapper function

callInsertFileWithParams();

Please format your posts! I cannot make sense of any of this unformatted text. It would be very kind to not just dump any text, code or error messages that you get, but instead take some time to write a well-structured and formatted posts, by sharing links to git repos that reproduce the issue.

Even if you don’t do that, that’s fine. We can try making sense of 1 or 2 messages, but if you’re expecting someone to go through 10 messages back to back of such text, I’m sorry that would not happen.

If you still need help, please share a link to a git repo that showcases the issue.

Sorry to be such a bother.
I finally discovered that i had not realized that all serverless functions needed to be named ‘handler’. Once I realized that all my problems went away.
Thanks for your help
Ken