Like what we’re doing? Star us on GitHub!

Generating Types Error with Azure

FireGuy_42
last month
9

Good Afternoon fellow Payloaders,



For some reason when running command

payload generate:types

(yarn payload...), I get an error relating to the Azure Storage Blob, this error is resolved when I hard code storageAdapter.ts, which for obvious reasons, cannot be left as the solution as it would pose a glaring security vulnerability.



Storage Adapter.ts


import { azureBlobStorageAdapter } from "@payloadcms/plugin-cloud-storage/azure";


const storageAdapter = azureBlobStorageAdapter({
  connectionString: process.env.AZURE_STORAGE_CONNECTION_STRING,
  containerName: process.env.AZURE_STORAGE_CONTAINER_NAME,
  allowContainerCreate:
    process.env.AZURE_STORAGE_ALLOW_CONTAINER_CREATE === "true",
  baseURL: process.env.AZURE_STORAGE_ACCOUNT_BASEURL,
});

export default storageAdapter;

Has anyone encountered a problem like this ?



Ok so adding

import dotenv from "dotenv/config"

in payload.config and adding

require('dotenv').config()

in storageAdapter.ts solves the issue



incase anyone has the issue later


/node_modules/@azure/storage-blob/dist/index.js:13642
    if (connectionString.startsWith("UseDevelopmentStorage=true")) {
                         ^

TypeError: Cannot read property 'startsWith' of undefined
    at extractConnectionStringParts (/Users/bcch-nicholas/Documents/GitHub/cardiac-backend/node_modules/@azure/storage-blob/dist/index.js:13642:26)
    at Function.fromConnectionString (/Users/bcch-nicholas/Documents/GitHub/cardiac-backend/node_modules/@azure/storage-blob/dist/index.js:24600:32)
    at Object.adapter (/Users/bcch-nicholas/Documents/GitHub/cardiac-backend/node_modules/@payloadcms/plugin-cloud-storage/dist/adapters/azure/index.js:14:66)
    at /Users/bcch-nicholas/Documents/GitHub/cardiac-backend/node_modules/@payloadcms/plugin-cloud-storage/dist/plugin.js:42:43
    at Array.map (<anonymous>)
    at /Users/bcch-nicholas/Documents/GitHub/cardiac-backend/node_modules/@payloadcms/plugin-cloud-storage/dist/plugin.js:38:164
    at /Users/bcch-nicholas/Documents/GitHub/cardiac-backend/node_modules/payload/dist/config/build.js:15:84
    at Array.reduce (<anonymous>)
    at buildConfig (/Users/bcch-nicholas/Documents/GitHub/cardiac-backend/node_modules/payload/dist/config/build.js:15:50)
    at Object.<anonymous> (/Users/bcch-nicholas/Documents/GitHub/cardiac-backend/payload.config.js:17:44)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.


TypeError: Cannot read property 'startsWith' of undefined
    at extractConnectionStringParts (/Users/bcch-nicholas/Documents/GitHub/cardiac-backend/node_modules/@azure/storage-blob/dist/index.js:13642:26)
    at Function.fromConnectionString (/Users/bcch-nicholas/Documents/GitHub/cardiac-backend/node_modules/@azure/storage-blob/dist/index.js:24600:32)
    at Object.adapter (/Users/bcch-nicholas/Documents/GitHub/cardiac-backend/node_modules/@payloadcms/plugin-cloud-storage/dist/adapters/azure/index.js:14:66)
    at /Users/bcch-nicholas/Documents/GitHub/cardiac-backend/node_modules/@payloadcms/plugin-cloud-storage/dist/plugin.js:42:43
    at Array.map (<anonymous>)
    at /Users/bcch-nicholas/Documents/GitHub/cardiac-backend/node_modules/@payloadcms/plugin-cloud-storage/dist/plugin.js:38:164
    at /Users/bcch-nicholas/Documents/GitHub/cardiac-backend/node_modules/payload/dist/config/build.js:15:84
    at Array.reduce (<anonymous>)
    at buildConfig (/Users/bcch-nicholas/Documents/GitHub/cardiac-backend/node_modules/payload/dist/config/build.js:15:50)
    at Object.<anonymous> (/Users/bcch-nicholas/Documents/GitHub/cardiac-backend/src/payload.config.ts:23:40)
(node:96745) UnhandledPromiseRejectionWarning: Error: Error: can't find the configuration file located at /Users/bcch-nicholas/Documents/GitHub/cardiac-backend/src/payload.config.ts.
    at build (/Users/bcch-nicholas/Documents/GitHub/cardiac-backend/node_modules/payload/dist/bin/build.js:35:15)
    at Object.<anonymous> (/Users/bcch-nicholas/Documents/GitHub/cardiac-backend/node_modules/payload/dist/bin/index.js:16:9)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    ...

    


So that will be more easily searchable by others



If this is a 'bad' or 'hacky' solution, please lmk



update: so the app builds, but does not serve (I run yarn build often during my development process when making potentiall breaking-changes)



if anyone gets why this might happen any and all feedback/assistance would be fantastic

on_yarn_payload_generate_types.png
package_json.png
on_yarn_build.png
  • Jarrod
    Payload Team
    last month

    I’m not sure you need the dotenv import in the adapter file, but try adding it to your server.ts file (also keep it in your payload config file)



    @FireGuy_42 did you give this a shot?

  • FireGuy_42
    3 weeks ago

    @Jarrod Hey Jarrod, yeah so without the

    // require('dotenv').config()

    in storageAdapter.ts file. the build errors out



    TypeError: Cannot read property 'startsWith' of undefined at extractConnectionStringParts (/Users/bcch-nicholas/Documents/GitHub/cardiac-backend/node_modules/@azure/storage-blob/dist/index.js:13642:26)


    Server.ts



    import express from "express"; import payload from "payload"; require("dotenv").config(); const app = express(); // Initialize Payload payload.init({ secret: process.env.PAYLOAD_SECRET, mongoURL: process.env.MONGODB_URI, express: app, onInit: () => { payload.logger.info(

    Payload Admin URL: ${payload.getAdminURL()}

    ); }, }); // Add your own express routes here // Redirect root to Admin panel app.get("/", (_, res) => { res.redirect("/admin"); }); app.listen(3001);


    still on 1.5.9

Open the post
Continue the discussion in Discord
Can't find what you're looking for?
Get help straight from the Payload team with an Enterprise License.Learn More