I am using Ghost as an NPM module, and I am trying to get it to work with a custom storage adapter. However, it is looking under \node_modules\ghost\core\server\adapters\storage instead of \content\adapters\storage for the custom storage adapter.
expected: ghost being able to find the module
actual: ghost looks in \node_modules\ghost\core\server\adapters\storage instead and unable to find the storage adapter
HI @wolleysesom, it sounds as though you may be missing the paths entry in your config file, see: https://docs.ghost.org/docs/using-ghost-as-an-npm-module#section-create-a-custom-config-file
Could you confirm this?
If this is not the case can you please provide your full config file so we can verify if this is a bug or not. Thank you 😄
It has it. Here is full config
{
"database": {
"client": "sqlite3",
"connection": {
"filename": "content/data/ghost-dev.db"
},
"debug": false
},
"server": {
"host": "127.0.0.1",
"port": "1337"
},
"auth": {
"type": "password"
},
"paths": {
"contentPath": "content/"
},
"storage": {
"active": "ghost-s3-compat",
"ghost-s3-compat": {
"accessKeyId": "blah",
"secretAccessKey": "blah",
"bucket": "blah",
"region": "blah"
}
}
}
Got similar issue while setting custom contentPath. Relevant chunk of my config:
"paths": {
"contentPath": "content/"
}
With this config Ghost keeps looking in PROJECT_FOLDER/node_modules/ghost/content instead of PROJECT_FOLDER/content. However, if I remove slash:
"paths": {
"contentPath": "content"
}
path resolves correctly.
The issue must be in this line:
https://github.com/TryGhost/Ghost/blob/master/core/server/config/utils.js#L42
paths.contentPath gets ovewritten if contains / (e.g. content/) and is set to Ghost root folder instead of project root.
@evenfrost Which storage adapter are you using?
@wolleysesom
Are you seeing this error?
IncorrectUsageError: We have detected an error in your custom storage adapter.
...
Error: Cannot find module '/ghost/core/server/storage/base'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/ghost/content/adapters/storage/ghost-s3-compat/index.js:16:17)
This is a wrong implementation in the ghost-s3-compat adapter. It tries to require a file from Ghost, which does not exist.
If i am adding a plain custom storage adapter, it works fine for me.
Let me know.
@kirrg001 I'm using custom theme which is not being loaded due to this bug. I'm referencing it here because similar one #8795 was closed as duplicate of this one.
I see. You are using Ghost as NPM module. This looks like a bug yeah. Sorry for trouble. We should use process.cwd() instead of going back in the folder hierarchy.
If a config path contains a trailing slash (e.g.content/), it's detected as relative path and get's transformed into an absolute path. If not, it's already absolute.
And now I'm stuck with exact issue related to using custom adapter. I'm using ghost-cloudinary-store and, when installing to content/storage/ghost-cloudinary-store directory, the error is thrown:
Error: Cannot find module '/*path_to_blog_dir*/node_modules/ghost/core/server/adapters/storage/ghost-cloudinary-store'
So it looks for the storage in wrong directory. My path config is:
"paths": {
"contentPath": "content"
}
However, when I change config to
"paths": {
"contentPath": "content/"
}
The not found error is still here, and another error occurs, which I've already mentioned before:
NAME: NotFoundError
CODE: ENOENT
MESSAGE: The currently active theme "gost" is missing.
(I'm using custom theme named 'gost').
Is there any workaround or at least schedule when it is going to be fixed? My blog development is pretty hung because of this.
If you set your contentPath to content, Ghost interprets this as absolute path. So you have to use the full path to your folder e.g. /Users/Kate/Ghost/content. This definitely works.
The relative usage is a bug content/ as said above, this needs a fix. It's a bit tricky when using Ghost as NPM module, because you execute Ghost from your cwd, but Ghost is inside node_modules.
The currently active theme "gost" is missing.
If you set a custom content path, your active theme must be located inside your custom path.
FYI: ghost-cloudinary-store is not compatible with 1.X yet, see https://github.com/sethbrasile/ghost-cloudinary-store/issues/12.
Yeah, I've already updated ghost-cloudinary-store to 1.X-compatible API here: https://github.com/goLance-LLC/ghost-cloudinary-store (based on another fork), and it works now BUT only if I move this module to inner folder of ghost module, e.g.
Error: Cannot find module '/*path_to_blog_dir*/node_modules/ghost/core/server/adapters/storage/ghost-cloudinary-store'
> cp -r /wherever-i-cloned-ghost-cloudinary-store /*path_to_blog_dir*/node_modules/ghost/core/server/adapters/storage
# works!
Though I guess it should look not in /*path_to_blog_dir*/node_modules/ghost/core/server/adapters/storage/, but rather in /*path_to_blog_dir*/content/adapters/storage/.
Yeah, I've already updated ghost-cloudinary-store to 1.X-compatible API here: https://github.com/goLance-LLC/ghost-cloudinary-store (based on another fork)
Cool. Would be helpful for others to PR your changes back to the original repository. As soon as you are ready :)
If you set your contentPath to content, Ghost interprets this as absolute path. So you have to use the full path to your folder e.g. /Users/Kate/Ghost/content. This definitely works, i've tested this.
Sure, will do when I test it a bit more.
If you set your contentPath to content, Ghost interprets this as absolute path. So you have to use the full path to your folder e.g. /Users/Kate/Ghost/content. This definitely works, i've tested this.
I absolutely agree on that, but how can I fix this error then:
Error: Cannot find module '/*path_to_blog_dir*/node_modules/ghost/core/server/adapters/storage/ghost-cloudinary-store'
Bump.
I'm having the same issue with the gcloud adapter:
Error: Cannot find module '/*PATH_TO_PROJECT*/node_modules/ghost/core/server/adapters/storage/gcloud'
@evenfrost @ric2z
Can you please try to set your content path to an absolute path?
paths: {contentPath: '/Users/..../content'}}
@kirrg001 tried setting content path to an absolute path. Still experiencing the same issue.
@kirrg001 I was trying this adapter https://github.com/thombuchi/ghost-google-cloud-storage, but it seems to be out of date. I'm now trying this other one https://github.com/O-io/ghost-storage-adapter-gcloud which seems to be working fine.
I'm experiencing this issue without a custom storage adapter. I'm hosting my blog on Digital Ocean with their one click app setup but further customized it by using Ghost as an NPM module and upgraded to v1.9. If I use an absolute path for contentPath my themes do not show up in the admin section, same if I use a relative path with an ending / slash. However, if I remove the ending / my themes show up. E.G. "contentPath": "content".
This issue only occurs in production, which is on a Linux VPS. I can use an absolute path in development on OSX just fine.
EDIT**: Issue has been solved, I didn't have all of the folders needed for a custom content path.
Hello,
I am also experiencing this issue. Is there a definite fix yet? I have tried using absolute paths for my storage and it still happens.
my config file (config.development.json)
{
"url": "http://localhost:8000/blog",
"server": {
"host": "0.0.0.0",
"port": 8000
},
"storage": {
"active": "Mongodb",
"Mongodb": {
"mongodbUrl": "mongodb://localhost:27017/ma000_db"
}
},
"paths": {
"contentPath": "content"
}
}
I have the file content/adapters/storage/Mongodb.js as well.
I have tried content, content/ and a full absolute path from the Users menu.
@jacobian Thanks for the update 👍
This is occuring for me using the Google Cloud Storage module
I am also running all this on Google App Engine
Ran into the same issue. I ended up creating a task that generates config.{env}.json on startup. That way I can do:
paths: {
contentPath: path.join(__dirname, '/content'),
}
Is this issue fixed? because the content path is still using the one inside node_modules..
@Narutuffy Not fixed. The issue is still open.
Still getting this issue. Can't load themes, storage adapters or anything. Always looking in /node_modules/ghost...
Having this issue also.
Generally I am trying to use one of (any one at this point hah!) the custom storage adapters — ie. S3 or GCloud — built into a custom docker file.
Will post back if I come up with a solution.
OK So the absolute path fixed this for me.
Since I am running Ghost inside of an official docker container (https://hub.docker.com/_/ghost/) my paths look like this:
"paths": {
"contentPath": "/var/lib/ghost/content"
},
I am still having a problem with S3 Storage Adapter (path to but that's a discussion for another time).
I also found an absolute path fixes this issue, but it's an annoying workaround. It would be great to get the root cause fixed, absolute paths should be optional at best.
Closing due to age and lack of traction. We're no longer actively supporting installing Ghost as an npm module. PRs are still always welcome.
@ErisDS ah - that's interesting, can you point me in the direction of this npm module support announcement? Tbh, as an npm module is our, and the primary use case of quite a few companies who pointed me in the direction of it as a blogging engine. I should probably let them know!
This is pretty much a bug regardless of whether you support ghost being installed as an npm module or not. @ErisDS it should be fixed.
@CMCDragonkai Please use our forum if you need help. If it turns out there is a bug in Ghost, we can raise a new bug issue 👍
@kirrg001 This is definitely a bug. Using content/ should not behave different from using content.
@kirrg001 agree about using a new bug for this, as the npm module part is a misonomer. I will raise one.
Most helpful comment
@kirrg001 agree about using a new bug for this, as the
npm modulepart is a misonomer. I will raise one.