Skip global xdn npm install

In guides like this one on Deploying Gatsby on the Moovweb XDN, if you already have XDN CLI installed globally, you can skip

npm install -g @xdn/cli

and proceed directly to xdn init which will install the xdn packages into the project, right?

Correct, though if it’s been a long time since you installed the XDN CLI, it might be a good idea to update with:

npm i -g @xdn/cli@latest

When you run xdn init, it installs the latest version of the CLI as a project dev dependency, so all commands you run in that project going forward will be using the latest version.

Hello! I just ran the gatsby example code form the docs and just wanted to add here that running gatsby serve as the first command after installation can result in an error as it get confused if there is no cache folder. If the user runs gatsby develop first then a cache folder is created and they can serve afterwards. This doesnt happen everytime, its a known issue in gatsby which was supposed to have been fixed a while ago (see: gatsby serve issue.

For ease of use when following the tutorial i would suggest changing the suggested command to gatsby develop instead.

Welcome, @molebox! Thanks for the info!

did you happen to catch the error so that we can include it here and help out anyone else who might run into it?

1 Like

Hey Howie!

Clean install then running gatsby serve =>

λ gatsby serve
warning Error: ENOENT: no such file or directory, open 'D:\HUNGRYBEARSTUDIO\MOOVWEB\gatsby-site-2\.cache\match-paths.json'
warning Could not read match-paths.json from the .cache directory
warning Client-side routing will not work correctly. Maybe you need to re-run gatsby build?
You can now view gatsby-starter-hello-world in the browser.
error Error: ENOENT: no such file or directory, stat 'D:\HUNGRYBEARSTUDIO\MOOVWEB\gatsby-site-2\public\404.html'

This is due to no public folder existing and also no 404.js file existing either. This starter from Gatsby should include a 404 but it doesn’t.

As I understand it, Gatsby serve, serves the build output from the public dir as to mimic a production build locally. But seeing as the application hasn’t been run yet, no public dir has been created yet so no static files are there to serve. Also, as mentioned above, they don’t provide a default 404 any more (im sure they used to…)

Hope this helps.

@molebox good catch. FYI our docs are open source and I created a PR with your proposed change

1 Like

Oh cool! I didn’t know they were open source. Thanks!

Related to this issue, if I clone a repo that already has the XDN CLI as part of package.json devDependencies and do an npm install, the xdn command isn’t recognized in the command line. I need to run npm i -g @xdn/cli to get it to work. What’s the recommended approach?

if XDN was added via xdn init then there should be scripts defined in the package.json like this:

  "scripts": {
    "xdn": "xdn",
    "xdn:dev": "xdn dev",
    "xdn:build": "xdn build",
    "xdn:deploy": "xdn deploy",

which you can run via npm run, e.g.

npm run xdn:dev

Okay, a lot of your docs, eg the Next ones, tell you to issue the xdn dev command directly