Running npm build before/after npm install - node.js

I'm not familiar with npm so I might be holding the wrong end of the shovel here...
There is a package on npm that I would like to modify and use in my own project. The package is angular-crumbs. I forked the source repo (https://github.com/emilol/angular-crumbs) into my own account (https://github.com/capesean/angular-crumbs) and then run npm install capesean/angular-crumbs -force. However, this produces a node_modules folder in my project that hasn't been built (and whatever else - as I understand it) with the commands in the source repo's package.json file:
"build": "npm run clean && npm run transpile && npm run package && npm run minify && npm run copy"
i.e. it doesn't have the types, the correct package.json file, etc.
So my question is, how do I get the properly-built files (including type definitions, etc.) from my own repo to install or build-after-installing in my target project?

I am not sure about what you're trying to do, are trying to work on the
angular-crumbs source code, or are you trying to use it in your own project as a dependencuy ?
Anyway, running npm install will install all your dependencies so that you can directly use them in your project, those dependencies don't need to be built after they are installed.
In your case you seem to have an angular application (which is completely different from node.js), usually to start an angular app you can run ng serve which will build your source code and run an angular server so you can access it on localhost.

Related

"vite is not recognized ..." on "npm run dev"

I'm using Node.js and npm for the first time, I'm trying to get Vite working, following the tutorials and documentation. But every time I run into the problem 'vite' is not recognized as an internal or external command, operable program or batch file. I have been trying to find a solution for 4 hours now but with no results.
I tried restarting pc, reinstalling node.js, several procedures to create vite project but in vain. I suppose it's my beginner's mistake, but I really don't know what to do anymore.
Commands and responses I run when I try to create a vite project:
npm create vite#latest
>> my-portfolio >> vanilla & vanilla
cd my-portfolio
npm install >>resp: up to date, audited 1 package in 21s found 0 vulnerabilities
npm run dev
resp:
> my-portfolio#0.0.0 dev
> vite
'vite' is not recognized as an internal or external command,
operable program or batch file.
try to install the packages to make it work
npm install or npm i
For this error use the following command on your terminal in the present working directory of the project
npm install
npm run dev
first, try to install a node package manager and then run npm run dev hope it will work
yarn add vite
on project folder to add vite,
and run
npm run dev
again.
remember to update your node version to 18, LTS from 17 might not support this installation.
update:
I try to fresh install again my Laravel 9.19, since i had update my node to version 18, npm install & npm run dev just work fine without yarn.
According to documentation https://vitejs.dev/guide/#community-templates
npm install
npm run dev
npx vite build
I found myself in the same situation.
The problem is vite.cmd is not in the system or user PATH variable, so it cannot be found when it is executed from your project folder.
To fix it, you should temporarily add the folder where vite.cmd is in your PATH variable (either for the entire system or your user). I recommend adding it just for your user, and keep in mind you should probably remove it after you stop working on that project, because this could affect future projects using the same build tools.
To do this:
My PC > Properties > Advanced system settings > Click on Environment Variables (alternatively just use the start button and begin typing Environment, you should get a direct link)
On "User variables" find "Path" and edit it.
Add a new entry for the folder where vite.cmd is. Example "C:\dev\reactplayground\firsttest\test01\node_modules.bin" Check your project folder to find the right path.
Make sure your close and open your console for this change to affect.
Go back to your project root folder and run "vite build", it should work now.
for me I've:
1 - excuted yarn add vite
2- and then npm install
work fine !
For me I had a project I created on one computer and it had this in devDependencies:
"vite": "^3.1.0"
I did pnpm install and it reported everything was fine, but I was getting the error. I ran pnpm install vite and it installed it again with this:
"vite": "^3.1.8"
After that it worked fine. So try using npm, yarn, or pnpm to install the vite package again and see if that works.
try npm install
then npm run build
Recently faced this error and I run
npm install
npm run dev
then the output was
VITE v3.2.4 ready in 1913 ms
THAT'S COOL 😎😎😎
reference LINK
You need Node version 15 or higher, I had the same problem because I was using an older version of it.
Needs to install all the packages in package.json and run again
npm i
npm run dev
For me this worked:
I changed NODE_ENV environment variable to development ( earlier it was production - which should not be the case, as dev-dependencies won't get installed by npm install or yarn )
Here is what to make sure before running npm install or yarn:
Make sure `NODE_ENV` environment variable is not set to `production` if you running locally for dev purpose.
'vite' is not recognized as an internal or external command, operable program or batch file.
> vite
'vite' is not recognized as an internal or external command,
operable program or batch file.
try to install the packages to make it work
npm install or npm i
The following works just fine!
npx vite build
npm i
npm run dev
I had the same challenge and I was finding the error
create-vite : command not found
I resolved by running the command:
npm i create-vite
From there you can continue with running the command:
npm create vite#latest
Reference:
https://www.npmjs.com/package/create-vite
npm install or npm i
helps with issue of 'vite' is not recognized
After I tried npm install
i could run the npm run dev after and it showed me the localhost

Why is Heroku telling me it cannot find a package.json in my module when I do a heroku push

I created my own npm package from a fork of react-coverflow. It appears to be working fine in my app locally using it this way: "npm install react-coverflow-mod" --save.
I can run my app using "run with debug (F5)" in VsCode and npm start on the client folder to start the React front end.
Then I do an npm run build on the client folder, and it works just fine.
When I do a heroku push it fails everytime with this error:
npm ERR! code ENOLOCAL
npm ERR! Could not install from "../../react-coverflow-mod"
as it does not contain a package.json file.
1. I know there is a package.json in the module because I can install it via "npm install react-coverflow-mod": https://www.npmjs.com/package/react-coverflow-mod
2. The installed module has a package.json file in it
3. My github repo has a package.json in it: https://github.com/leroyvaughan/react-coverflow
I'm not sure how I can fix this. Do I need a package.json to go into the /Dist folder? What is wrong here with Heroku.
It seams like heroku try to install a package from a relative path instead of the published name. That would perfectly explain why you can run locally but not on a production environment.
Open your project and search for the exact string displayed in your log: "../../react-coverflow-mod" and you should be able to find quickly where it is.
If you run on a unix system (don't know about windows) you can do a search using grep:
grep -rnw '/path/to/somewhere/' -e '../../react-coverflow-mod'
Make sure it includes your root folder which contain package.json, and might we wise to ignore node_modules which is always massive.

NodeJS - npm install practice

Created new folder and did npm install serve in it.
It created package-lock.json and node_modules/ folder.
When I run in the same folder serve it shows error:
command not found: serve
What is the way to install?
I am using: npm#6.5.0
My dev environment is MACOS
I read a great many pages on this topic and nothing worked until I tried the following
./node_modules/.bin/serve -s build
Also if you are using VS CODE you may want to bring up the terminal window outside of VS CODE - this seems to have snared a lot of people.
First of all, you should start your project running
npm init
This will create the package.json file.
Then, you can install the serve package globally.
npm install -g serve
And now you can run serve.
The serve binary was not found because the operating system cannot locate it in the PATH environment variable.
When you do the npm install serve command. The serve module is only installed into the node_modules directory found under the the project folder. Unless you explicitly include the absolute path of this node_module directory as part of your PATH env var, the OS won't know where to find serve.
Like others say, the typical practise would be to install the module using the -g flag. G means global.
When -g is used, npm will put the binary in its node directory somewhere and this this directory would have been included as part of your PATH when you install node, thus making the any new binary discoverable.
If the node.js module has a "command" and you want to run it without installing the module globally(npm install -g serve). You can run it like ./node-modules/.bin/command from the root folder of the project.
Now, what is generally used is npx, so that you can from within a project easily run any of the binaries within its local node_modules or your system's global node_modules/ and any other commands on the $PATH.
For example, here we install webpack as a local dependency. You can image doing this in a folder after running npm init. Then we run webpack without having to worry about referencing the bin file:
$ npm i -D webpack
$ npx webpack

Making "sudo npm install --save-dev gulp" in Maverics nothing's happens

I'm trying to test Gulp and I find this problem.
I installed Gulp globally with: sudo npm install -g gulp.
Then I was created the folder: mkdir my-gulp
cd my-gulp
And the I try to do this: sudo npm install --save-dev gulp
It seems work fine, no errors, but my folder my-gulp continues empty.
I can see in console, this line:
gulp#3.8.6 ../../node_modules/gulp
And I thinkig the problem is here "../../", I think it must be "gulp#3.8.6 node_modules/gulp"
What do you think? Maybe is something about $PATH?
First, you should never run npm via sudo for local packages. (In fact, you shouldn't run it as root ever, but that's a different, more complex issue to solve.)
Second, you need to initialize NPM before you can install packages. It sounds like you didn't do this.
There's two ways:
If you have an existing package.json, which contains the required information about a project, you can copy it into your folder, then edit in a text editor of your choice to get started. If the package.json includes existing dependencies, you can either remove them, or run npm i in the folder to install them.
If you are starting fresh, run npm init to set up a new package.
Once you have a valid package.json, you can install packages into your application.
As to why you are seeing ../../gulp, I'm guessing you have a package.json further up the file tree somewhere.

Jenkins script quitting prematurely when using npm install on Windows

In my Jenkins job I want to build a JavaScript app using Grunt. The Jenkins build scripts creates a build directory (if it doesn't already exist), changes to that directory and runs:
npm install grunt
npm install grunt-zip
grunt --gruntfile=[something]
(Of course grunt-cli is installed globally.) When I build the job, the first statement causes Grunt and dependencies to be pulled down as expected. However, the job then terminates successfully:
Archiving artifacts
No emails were triggered.
Finished: SUCCESS
The second npm install is not run. Any idea why the script is terminating after running npm install instead of continuing to the subsequent statements?
So it turns out that npm is a batch file, not an executable, so it needs to be invoked using call from the Jenkins script:
call npm install grunt
i would recommend not using the local grunt / nodejs install, but instead getting jenkins to do this for you!
it's much easier and means there's less coupling to system specific installs and variables.
steps:
a) use nodejs jenkins plugin + get it to install nodejs on machine/grunt-cli -> Jenkins integration with Grunt
b) populate your package.json with any nodejs dependances required, eg grunt/grunt-zip etc
c) when running grunt just do a "npm update" before "grunt" command
that way your not doing explicit npm install, it's all configured from your package.json, and your build scripts will be less brittle, and your developers can use the same steps as the build server, eg "npm update;grunt" locally same as build server
For future googlers:
use command chaining for this.
This works:
npm install && npm install install grunt-zip
This wont work:
npm install
npm install grunt-zip

Resources