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

Unclear how to use local plugins #3251

Closed
MrToph opened this issue Dec 17, 2017 · 2 comments
Closed

Unclear how to use local plugins #3251

MrToph opened this issue Dec 17, 2017 · 2 comments

Comments

@MrToph
Copy link

MrToph commented Dec 17, 2017

Description

I can't get local plugins to work.
I followed the documentation, but it then throws an error if I leave the plugin's package.json as an empty object {}. (See the JSON.parse error below)
When I specify a main field in the package.json, I don't get the error but my plugin seems to not be executed at all.

The documentation page just tells to create an empty package.json and a gatsby-node.js, but if you look at actual plugins in this repo, their structure is completely different. For example here, the main field is also specified and points to an empty index.js file, while the gatsby-node.js file is inside a src folder and not on the plugin's root.

This is all really confusing to me, and doing it as specified in the documentation doesn't work for me.

Environment

Gatsby version: 1.9.119
Node.js version: v8
Operating System: Windows 10

File contents (if changed):

gatsby-config.js:

plugins: [
    {
      resolve: `local-plugin`, // this does not need to be a relative path, doesn't it?
      options: {
        // Setting a color is optional.
        color: `tomato`,
      },
    }
]

Actual result

Running gatsby-develop throws an error:

error UNHANDLED REJECTION


  SyntaxError: Unexpected token / in JSON at position 5

  - JSON.parse

  - load-plugins.js:65 resolvePlugin
    [gatsby-starter-blog-master]/[gatsby]/dist/bootstrap/load-plugins.js:65:32

  - load-plugins.js:147 processPlugin
    [gatsby-starter-blog-master]/[gatsby]/dist/bootstrap/load-plugins.js:147:27

  - load-plugins.js:168
    [gatsby-starter-blog-master]/[gatsby]/dist/bootstrap/load-plugins.js:168:28

Expected behavior

What should happen?

My plugin should be executed.

@jquense
Copy link
Contributor

jquense commented Dec 17, 2017

plugins should be in in a plugins directory under your package root, and have a package.json, check out https://github.com/jquense/react-widgets/tree/master/www which has a local plugin!

@MrToph
Copy link
Author

MrToph commented Dec 17, 2017

Thanks, setting it up like in your project works 👍

Not sure what I did differently, I couldn't reproduce my JSON parse error anymore, even with an empty package.json

The other times it just looked like it was not working, because I made a default export like in remark-plugins, and did not use one of the provided hooks.

We can close this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants