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

custom storage adapter path when using ghost as an npm module #8754

Closed
wolleysesom opened this issue Jul 26, 2017 · 33 comments
Closed

custom storage adapter path when using ghost as an npm module #8754

wolleysesom opened this issue Jul 26, 2017 · 33 comments
Labels
bug [triage] something behaving unexpectedly help wanted [triage] Ideal issues for contributors to help with server / core Issues relating to the server or core of Ghost

Comments

@wolleysesom
Copy link

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.

Steps to Reproduce

  1. use ghost as an npm module
  2. put a custom storage adapter under \content\adapters\storage
  3. update config to have a "Storage" section

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

Technical details:

  • Ghost Version: 1. 0. 0
  • Node Version: 6.11.1
@cobbspur
Copy link
Member

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 😄

@wolleysesom
Copy link
Author

wolleysesom commented Jul 26, 2017

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"
}
}
}

@ErisDS ErisDS marked this as a duplicate of #8795 Jul 31, 2017
@ErisDS ErisDS added bug [triage] something behaving unexpectedly help wanted [triage] Ideal issues for contributors to help with labels Jul 31, 2017
@evenfrost
Copy link

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.

@kirrg001
Copy link
Contributor

@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.

@evenfrost
Copy link

@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.

@kirrg001
Copy link
Contributor

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.

@kirrg001 kirrg001 added the server / core Issues relating to the server or core of Ghost label Aug 10, 2017
@evenfrost
Copy link

evenfrost commented Sep 14, 2017

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.

@kirrg001
Copy link
Contributor

kirrg001 commented Sep 14, 2017

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 sethbrasile/ghost-cloudinary-store#12.

@evenfrost
Copy link

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/.

@kirrg001
Copy link
Contributor

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.

@evenfrost
Copy link

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'

@ric2z
Copy link

ric2z commented Sep 25, 2017

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'

@kirrg001
Copy link
Contributor

@evenfrost @ric2z

Can you please try to set your content path to an absolute path?

paths: {contentPath: '/Users/..../content'}}

@ric2z
Copy link

ric2z commented Sep 25, 2017

@kirrg001 tried setting content path to an absolute path. Still experiencing the same issue.

@ric2z
Copy link

ric2z commented Sep 25, 2017

@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.

@cleversprocket
Copy link

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.

@jscohen
Copy link

jscohen commented Dec 4, 2017

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.

@kirrg001
Copy link
Contributor

kirrg001 commented Dec 5, 2017

@jacobian Thanks for the update 👍

@nohe427
Copy link

nohe427 commented Feb 25, 2018

This is occuring for me using the Google Cloud Storage module

@nohe427
Copy link

nohe427 commented Feb 25, 2018

I am also running all this on Google App Engine

yusuiked pushed a commit to yusuiked/blog that referenced this issue May 20, 2018
…roblem that goes to see the module under `node_modules /` as a relative path.

refs: TryGhost/Ghost#8754
@mattdrose
Copy link

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'),
}

@Narutuffy
Copy link

Is this issue fixed? because the content path is still using the one inside node_modules..

@kirrg001
Copy link
Contributor

@Narutuffy Not fixed. The issue is still open.

@antony
Copy link

antony commented Nov 14, 2018

Still getting this issue. Can't load themes, storage adapters or anything. Always looking in /node_modules/ghost...

@necevil
Copy link

necevil commented Nov 29, 2018

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.

@necevil
Copy link

necevil commented Dec 20, 2018

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).

@antony
Copy link

antony commented Dec 20, 2018

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.

@ErisDS
Copy link
Member

ErisDS commented Jan 2, 2019

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 ErisDS closed this as completed Jan 2, 2019
@antony
Copy link

antony commented Jan 3, 2019

@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!

@CMCDragonkai
Copy link

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.

@kirrg001
Copy link
Contributor

@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 👍

@CMCDragonkai
Copy link

@kirrg001 This is definitely a bug. Using content/ should not behave different from using content.

@antony
Copy link

antony commented Mar 18, 2019

@kirrg001 agree about using a new bug for this, as the npm module part is a misonomer. I will raise one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug [triage] something behaving unexpectedly help wanted [triage] Ideal issues for contributors to help with server / core Issues relating to the server or core of Ghost
Projects
None yet
Development

No branches or pull requests