Unable to implement any ghost storage adapter

If you’re looking for help, please provide information about your environment. If you delete this template and don’t provide any information, your topic will be automatically closed.

If you aren’t running the latest version of Ghost, the first thing we’ll ask you to do is update to the latest version of Ghost.

  • What’s your URL? local installation

  • What version of Ghost are you using? 5.94.1
    And

  • How was Ghost installed and configured?
    - npm i -g ghostcli then ghost install local

  • What Node version, database, OS & browser are you using?

  • Debug Information:
    OS: Microsoft Windows 11 Home, v10.0.22631
    Node Version: v20.15.1
    Ghost Version: 5.94.1
    Ghost-CLI Version: 1.26.1
    Environment: development
    Command: ‘ghost start’

  • What errors or information do you see in the console?
    Error [ERR_REQUIRE_ESM]: require() of ES Module C:\Users\ziggy\gitstuff\sw-milkyway-home\ghost\local2\content\adapters\storage\S3CustomAdapter.js from C:\Users\ziggy\gitstuff\sw-milkyway-home\ghost\local2\versions\5.94.1\core\server\services\adapter-manager\index.js not supported.
    at AdapterManager.getAdapter (C:\Users\ziggy\gitstuff\sw-milkyway-home\ghost\local2\versions\5.94.1\node_modules@tryghost\adapter-manager\lib\AdapterManager.js:114:27)
    Instead change the require of S3CustomAdapter.js in C:\Users\ziggy\gitstuff\sw-milkyway-home\ghost\local2\versions\5.94.1\core\server\services\adapter-manager\index.js to a dynamic import() which is available in all CommonJS modules.
    at AdapterManager.getAdapter (C:\Users\ziggy\gitstuff\sw-milkyway-home\ghost\local2\versions\5.94.1\node_modules@tryghost\adapter-manager\lib\AdapterManager.js:107:32)
    at Object.getAdapter (C:\Users\ziggy\gitstuff\sw-milkyway-home\ghost\local2\versions\5.94.1\core\server\services\adapter-manager\index.js:31:31)
    at Object.getStorage (C:\Users\ziggy\gitstuff\sw-milkyway-home\ghost\local2\versions\5.94.1\core\server\adapters\storage\index.js:14:27)
    at setupSiteApp (C:\Users\ziggy\gitstuff\sw-milkyway-home\ghost\local2\versions\5.94.1\core\frontend\web\site.js:85:71)
    at module.exports (C:\Users\ziggy\gitstuff\sw-milkyway-home\ghost\local2\versions\5.94.1\core\server\web\parent\frontend.js:22:58)
    at initExpressApps (C:\Users\ziggy\gitstuff\sw-milkyway-home\ghost\local2\versions\5.94.1\core\boot.js:248:68)
    at bootGhost (C:\Users\ziggy\gitstuff\sw-milkyway-home\ghost\local2\versions\5.94.1\core\boot.js:556:32)

  • What steps could someone else take to reproduce the issue you’re having?

  • create a ghost server with ghost install local, then follow the documentation to create a custom storage adapter

I simply am trying to get my ghost server to run with a custom server adapter that uploads to s3. The server will not import my adapter module correctly as a js module or a commonjs. The documentation or forums do not show an example of a custom implementation that is successful.

My implementation is simple:

‘use strict’;

const BaseAdapter = require(‘ghost-storage-base’);
const AWS = require(‘aws-sdk’);
const { v4: uuidv4 } = require(‘uuid’);
const path = require(‘path’);
const mime = require(‘mime-types’);

class S3CustomAdapter extends BaseAdapter {
constructor(config) {
super();
this.s3 = new AWS.S3({
accessKeyId: config.key,
secretAccessKey: config.secret,
region: config.region,
});
this.bucket = config.bucket;
}
}

module.exports = S3CustomAdapter;

I implemented all of the functions according to the documentation, but here are some things that I want to give feedback about as they unclear when doing it

  1. If the custom adapter needs a node module the documentation does not explain where or how to install this module so that is resolves correctly.
  2. the documentation does not explain how to pass a configuration to your custom adapter
  3. The documentation does not explain how to use the {adapter}:{feature} format in the configuration to explicitly handle certain file types.
  4. Most of the recommended modules in the documentation for storage adapters, especially the s3 ones are out of date and do not work with the latest version of Ghost and should be removed.

I’m hoping the issue can be identified whether it is a bug or something that I did wrong, I can successfully create and run the ghost server with a custom storage adapter, and that other developers trying to manage a custom ghost server will find this solution useful.