Sanity not starting anymore, even though I'm in the right file - sanity

I'm making sure to type in sanity start in the right file pathway (for me its the Website folder). Its been working for me fine the past week and up till today, but not anymore. I'm worried I've messed with my Sanity files somehow, its my first time trying to use a backend so its possible I've done something I shouldn't have (I was having confusions around sanity client last night, and that my current sanity version didn't support my current react version). I think I remember trying to upgrade sanity through the terminal, but otherwise I don't remember making any other changes. I'm currently having a big issue trying to fetch data from the backend, so that's been a whole thing too.
This is the whole message I'm getting in the command prompt:
#sanity/core not installed in current project
Project-specific commands not available until you run `sanity install`
Error: Command "start" is not available outside of a Sanity project context.
Run the command again within a Sanity project directory, where "#sanity/core"
is installed as a dependency.
at _.runCommand (C:/Users/kiras/AppData/Roaming/npm/node_modules/#sanity/cli/bin/sanity-cli.js:3608:1340)
at t.exports (C:/Users/kiras/AppData/Roaming/npm/node_modules/#sanity/cli/bin/sanity-cli.js:1980:2422)

This is my first comment so I apologize if I'm not following some standard that StackOverFlow-culture has.
I got the same error as you, as shown below.
Error: Command "start" is not available outside of a Sanity project context.
Run the command again within a Sanity project directory, where "sanity"
is installed as a dependency.
at CommandRunner.runCommand (~/.nvm/versions/node/v18.12.1/lib/node_modules/#sanity/cli/lib/_chunks/cli-3984b311.js:17742:33333)
at Object.runCli (~/.nvm/versions/node/v18.12.1/lib/node_modules/#sanity/cli/lib/_chunks/cli-3984b311.js:17745:2460)
Yesterday everything was fine but today, Sanity was not working. I was in the right file and directory, and my JSON package was formatted properly as well. I tried installing and deleting many things but nothing worked. I ran this command in the studio directory:
sanity install
After that prompt, I got the following:
The `#sanity/core` module is not installed in current project
Project-specific commands not available until you run `npm install`
? Package manager to use for installing dependencies? npm
Then... I got a ton of "npm WARN deprecated" warnings but then I tried:
sanity start
and it worked? I hope this helps, goodluck!
If this doesn't work, make sure you have the following:
Scripts are Correct in studio/package.JSON
"scripts": {
"start": "sanity start",
"build": "sanity build"
},
If you accidentally deleted some JSON file, you can use:
npm i
to get it back, I made that mistake but make sure you're in the proper directory (web or studio).
Apologies for the long response, but this should work, a lot of the responces gave the same repetitive answer ("cd into sanity folder by writing cd sanity and then sanity start") and it frustrated me seeing the same thing 715,143,763 times lol
Good luck!

Related

How to get the version of a remote npm package using a bin script

I'm trying to set up an npx script to create a template project.
In package.json I have:
"bin": {
"init": "bin/init"
}
In the init script I'm using tag='v'$(npm pkg get version | tr -d '"') to get the version of the package. I then use git clone --depth 1 --branch $tag https://github.com/matriarx/typescript.git to clone that specific repository for that specific tag.
When I do yarn link and try use it locally, from within that specific project, it works because it's able to correctly pick up the package.json version. So the above only works if it's run inside an existing project. However that's not what I want to do.
I want to enable someone to run it even if they have nothing locally, by simply doing npx #matriarx/typescript init and it should create the new project by cloning it. More than that I want them to be able to clone any specific version by using npx #matriarx/typescript#0.0.1 init in order to clone a specific version.
However it seems that anything I try is only able to get the version from a local package.json that already exists.
I could just clone the current existing repository without specifying any tag, but that would defeat the point of having releases, then it would just clone any current code completely disregarding the release. So it has to clone the tagged release.
How can I get the remote package version stored on npm from the bin script without having anything locally before hand?
Alternatively is there a better way to do what I'm trying to do?
EDIT: I ended up just hardcoding the version in the script, which works but it sucks because it's tedious to have to update it every time I bump the version. Though for now I still don't know a better way to do it.
After some more time messing around I figured out there is a standard way of doing it, at least since npm 7.
If you have a project like example then you can create a completely separate project called create-example with a bin script.
When you use npm init example, npm will automatically search for a package prefixed with "create-" and execute its main bin script. So when running npm init example it will search for that create-example package and execute the bin script, which will install the example package.
This is how most of the bigger packages like react and next do it.
This approach comes with some disadvantages that I really don't like, for example it will show the incorrect dependencies on npm and it will cause you to have to maintain multiple projects and semvers on different projects. However it will also allow you to create a clean separation between the actual project and the installation of that project.
For some projects it might also make a lot more sense. For example if you have a project that doesn't have a package.json at all and you want to create a setup for it, it wouldn't make sense to create an npm package inside that project just for that. Instead you can create a separate "create-project" package just to set it up and keep npm out of the actual project. In other words it gives you a neat way to create bin scripts for a completely separate project that doesn't have anything to do with npm.
You could also just have created a normal shell script and execute it using curl but I guess npm just gives you another way to do it.
You still have to hardcode the version in that "create-project" package, I still have not seen a way to automatically determine the version from a remote package. The only way I've managed to do that is to completely download the package, get the version, then delete it, but that would be terrible for people with a slower internet connection or limited data.

Use different versions of the same package in dev or prod?

(not a native speaker, sorry if things don't seems clear)
We are devs for a clients and we work with others devs from another company. The other devs make us a package that we sometimes change this in it, then submit the changes in a pull request.
So we end up having a local version of the package and the official version. And so we want to use the local version in dev (where we might make little changes in the package to match what the client want), and the official in prod (where our changes and other devs changes are merges).
I will show an example that don't work but that can help understand the idea:
[...]
"dependencies"{
[...]
"package":"prod-package"
},
"devDependencies"{
[...]
"package":"local/version/of/package"
},
and so, we should have this:
npm build # use local/version/of/package
npm build --prod # use prod-package
I'm not really good with npm (in fact, beside npm install and npm remove, I basically know nothing), so I might ask something obvious, but I can't find the answer anywere.
Have you tried using npm-link to link to the local version of the package you are consuming? That way, you could still commit your changes to the package back to the vendor.
https://docs.npmjs.com/cli/v8/commands/npm-link
You would essentially run npm link in the checked-out-from-VCS (git?) package folder, then you switch back to your project where you are consuming that package and run npm link {name-of-npm-package}
This would allow you to develop on that version locally, make your changes (and they will show up on VCS for easy pull request management).

zsh: command not found tickets (macOS)

first of all, I'm not really good into this, but I installed something with npm.
npm i tickets
npm install -g tickets
Installation was succesfull and it worked fine. Afterwards, I wanted to look into the sourcecode to find sth. I needed to edit. I open the folder "tickets" into visual studio code and searched through the sourcecode but couldn't find it. Then I wanted to start it again and then it started - getting this error:
zsh: command not found: tickets
When I was working in visual studio code I was in the "tickets" directory. So, like in the beginning when It worked, I switched to home directory but I still keep getting the error. I have no idea why it doesn't work not. Basically, I did nothing except being in a different directory.
I tried to fix it with exporting the path (using a MacBook):
export PATH=$PATH:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:$HOME/npm/bin
But did not work out.
I'm struggling now by testing out different solutions I found. Hope someone can help me out in a noob-friendly way! Thanks!
npm i installs a package in the current project. If you want it to be available from anywhere, you need to install it globally - npm install -g tickets (you'll probably need sudo in order to do that, though).

NPM on LEMP cannot find module, wrong path

Total Linux noob here. I am trying to configure a Pleroma development environment on DO droplet. Installed LEMP, installed SSL, installed PostgreSQL, installed Pleroma, so far so good.
Then I installed Node, NPM, cloned Pleroma-FE (apparently it installs in /user/pleroma-fe folder). I am following the very brief build instructions here:
https://git.pleroma.social/pleroma/pleroma-fe
When I get to the command in those build instructions: npm run build
I am getting error: Error: Cannot find module '/user/build/build.js'
It's because actual path to the build file is /user/pleroma-fe/build/build.js
Apologies if this is a duplicate. I see other questions about this.
Fixing npm path in Windows 8 and 10
and the reply seems to set the PATH. This answer might apply to my situation. But my question is: it is clearly already looking in a well defined path (which is different from all the other questions, which don't seem to have well defined path in the error message). But it is the wrong path. How do I make it look in the correct path?
I tried the npm command and specified the complete path, and every variation. and none worked. So it seems fixing the path won't fix this problem.
Sorry I do not currently know enough Linux to be able to fix this. I tried to tag this with Pleroma but I don't have enough reputation to create a new tag. Any help is much appreciated. Thanks in advance.
I continued to work on this with some help of a Linux admin on Fiverr and the Pleroma developers chat with success, thanks to all.
The solution did not involve changing the path. There were several different things going on. First, I needed to change directory into the development project source folder:
cd pleroma-fe
Once I did that, npm found the build module. Next issue was Node was very old and I needed to get the latest version. I used the instruction here for NodeJS (10):
https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions
Next issue was npm was missing some modules. This was fixed with:
npm install
After that the build completed with no errors.
npm run build
After a successful build, you will see a list of files that have changed as a result of the build.
Next issue is that simple changes in HTML text were not live, ie. not reflected in the refreshed web page. This is fixed by copying all the resulting build files to the production folder using rsync. In my case the command was:
rsync -av /user/pleroma-fe/dist/ /home/pleroma/pleroma/priv/static/
Pleroma is a neat Twitter-like user interface to ActivityPub fediverse, it includes a Mastodon UI as well, and thanks to the developers for making it free and open source.

New project with GULP

I made a project using GULP and I downloaded several modules with the NPM cmd. For a new project, should I copy/paste my old project with the files "gulpfile.js", "package.json" and the folder "node_module" or i have to redownload all the modules ? I tried to copy/paste and it worked perfectly, but maybe there is an another way to do it (like download each module with one command line) ?
Thank you !
Copying your old package.json file into your new project is perfectly reasonable when you also use a copy of your existing gulpfile.
Now, instead of copying your node_module folder just run npm install. It does exactly the same thing as copying and pasting but with the added bonus of checking package versions, deprecated dependencies, and so on...
Quick tip: If you ever run into problems as I have deleting/removing packages given that theirs paths might be longer than what the OS allows use the tool rimraf. Install it globally and then you can call rimraf on anything. CAUTION! this tool will erase everything no questions asked