andrewbranch / gatsby-remark-vscode

Gatsby plugin to provide VS Code’s syntax highlighting to Markdown code fences

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot find theme module error

HarshilShah opened this issue · comments

Hi there, I just updated to v2 and migrated over the one extension I was using, and for some reason the theme’s package.json isn’t being found and so I’m seeing this error.

ERROR #85901  GRAPHQL

There was an error in your GraphQL query:

Cannot find module 'night-owl/package.json'
Require stack:
- /usr/local/lib/node_modules/gatsby-cli/lib/index.js

   1 | query usersharshilDeveloperWebblogsrctemplatesblogPostJs2005402143($slug: String!) {
   2 |   markdownRemark(frontmatter: {slug: {eq: $slug}}) {
>  3 |     html
     |     ^
   4 |     frontmatter {
   5 |       title
   6 |       description
   7 |       image {
   8 |         childImageSharp {
   9 |           original {
  10 |             src
  11 |           }
  12 |         }
  13 |       }

File path: /Users/harshil/Developer/Web/blog/src/templates/blog-post.js
Url path: /blog/updating-ui-for-iphone-x
Plugin: none

My setup is:

{
  resolve: `gatsby-remark-vscode`,
  options: {
    theme: {
      default: 'Light+ (default light)',
      dark: `Night Owl (No Italics)`
    },
    extensions: ['night-owl'],
    injectStyles: false
  }
}

and I’ve got the night-owl theme installed via npm. I thought it might be an issue with the theme itself so I tried the synthwave one mentioned in the readme but that’s showing the same exact error too

Hmm weird, I can’t reproduce this in the example site included in the repo... When you say you installed it via npm, you did npm i sdras/night-owl? And ./node_modules/night-owl/package.json is definitely there?

I installed it via sdras/night-owl-vscode-theme since the migration guide stated using the repo name, gonna try out just sdras/night-owl too. Fwiw, installing that way did work and the package along with it’s package.json is installed correctly.

Update: Seems like npm install sdras/night-owl-vscode-theme is the correct one, the other one just fails

Yeah woops sorry, I meant npm i sdras/night-owl-vscode-theme. That’s what I ran. But even though the repo is named night-owl-vscode-theme, npm successfully installs that into node_modules/night-owl for me. Is that not what you’re seeing too?

Yep, seeing it installed there correctly, but for some reason it isn’t being picked up. No issues if I use the default themes, but it’s only when I have the custom theme specified as an extension that I get that error.

A thing I noticed though is that a couple of times it would fail silently; it still would render the same way but there would be no error messages in the console. Not sure if it’s relevant though.

The site is private at the moment but I’m happy to share the source with you if you’d like a look.

That’s so strange. Yeah, I don’t have any clues without taking a look at the code.

Just added you to the repo, the work on migrating to v2 so far is on the vscode branch.

git checkout vscode
npm install
npx gatsby build

works for me—

npx gatsby develop

image

seems to be working, besides the styling removed by injectStyles: false.

Dumb question, but have you tried rm -r .cache? I think it’s supposed to be invalidated whenever you change gatsby-config.js, but I hear that cache invalidation is hard.

Removing the cache didn’t do anything, but I cloned a fresh copy of the site and rebuilt it and that seems to work? Not entirely sure what’s going on here, wonder if it’s something related to node_modules because I genuinely can’t think of anything else. Gonna play around with this.

Update: Nuking node_modules and rebuilding did the trick! 🎉 Thanks a lot for the help with this!

Huh, strange! Hope this doesn’t come back to haunt me later 😐

Okay so turns out this whole thing ended up being an entirely different and stupid issue on my part. The bit about node_modules was a bit of a mistake. I’d accidentally removed and rebuild node_modules for the new clone rather than the install that wasn’t working. Turns out the issue really was my gatsby-cli version was outdated, and it was running it through npx that made it work 🤦🏽‍♂️

Hi @andrewbranch, I'm having the same issue, was there ever a fix for this? Seems to work fine if I run npx but not npm. Tried updating to the latest CLI aswell, current version 2.11.3 but still no luck.

@kennytranco My understanding of the problem is that the global (triggered by running gatsby) and local (triggered by running via npx) versions of Gatsby were out of sync, and the local variant was up-to-date while the global one was outdated. Are you sure both are the same in your case?