"Could not find task 'npm'" error in VS Code - javascript

Whenever I try to run a JavaScript or Python file in VS Code this error message appears:
I have tried reinstalling node but it still wont work. When I click on configure I am shown these options. When I click on any of them I am directed to this json file.
I am pretty new to coding so sorry if I missed anything. Let me know if I did, I would be happy to provide it.
PS: I see that my interpreter at the bottom left is set to python, but clicking on it I am not getting any options that make sense to me. And also, this same thing happens when I try to run a python file.

if you want to run npm commands you should go to a directory that your nodejs is installed... if you want to run npm commands in other directories you should go to the directory that you want and then run cmd and type in the commant
set path=C:\Program Files\nodejs\
then you can run all of the npm commands in your directory

In my case I didn't open the right directory (I was inside the project parent directory). Maybe it would help someone else who get into

The list of commands you see in there are what is called VS Code tasks, see details here - https://code.visualstudio.com/docs/editor/tasks
In your particular case they have been created to run npm commands from within VS Code without opening the terminal. These require a package.json file at the root of your project directory with corresponding script commands.
An example package.json file might look something like this:
{
"scripts": {
"install": "npm install",
"test": "node test.js",
"start": "node index.js"
}
}
WARNING: your project should have a package.json file with scripts that match what has been specified in your tasks.json file.
Please provide a working copy of you application somewhere online, e.g. CodeSandbox, if you require more help.

Related

How do I get NPM commands to run properly in Eclipse?

I have a usable workflow that I want to make better. I'm building a JS library, and the way I am executing smoke tests on code is by using webpack to package the library and write it to a file that is included in an HTML file for viewing the effects of the code.
To do this, I make changes to the file in Eclipse, save it, then I must leave Leave eclipse and go to Terminal to run "npm run buildInbrowser" to execute "webpack --config inbrowser.config.js".
The configuration works perfect with regards to webpack, the configuration, and the npm setup, but when I try to configure eclipse to run those commands, it brings up an error: "env: node: No such file or directory" I've attached screenshots of my launch NPM configuration.
My system is MacOSX Catalina using Nodeclipse, npm v9.3.1 and node 16.18.0.
Again, there is no issue with me running these commands in terminal, but they won't run through node. This makes me think it's something simple that I overlooked.
As nitind pointed out, I had incorrect syntax on the PATH variable for eclipse, which was causing the problem. Also noted is that Eclipse did not populate my path variable by default, so i did have to manually enter it in. See the screen shot for the fix.

Errors when I run NPM start

I am working on building a RESTful API using Node, express, and MongoDB.
During the beginning stages of this project, when I attempt to run the "npm start", I get a few lines of errors.
The errors I'm getting
I'm not sure what the problem could be as I have added the "start" under scripts in the package.json file and I have initialized node and well as having installed nodemon. Please may I ask for assistance?
Try the following:
Make the file index.js
Try the command node app.js, if it works then your node_modules is in the wrong place or you dependencies are probably not installed properly.
Try uninstalling and installing dependencies.

Writing a script to automate npm command

I am working on an angular js project and I would like to automate The following two commands.
./node_modules/protractor/bin/webdriver-manager update
./node_modules/protractor/bin/webdriver-manager start
The issue is that I am working on a small angular project on github. I added all dependencies required to my package.json, However when my friend pulled it from git he was able to install protractor but he could not get webdriver to start unless he ran the above two commands. So i wanted to write some script to automate it and better yet even add protractor ./conf.js to it.
So I did research and I am aware that I can write a npm script but I was not able to find a proper document that showed where to write the script and how to execute it. I would appreciate all suggestions.
You can add a scripts property to your package.json with the command you wish you run.
"scripts": {
"prostart": "./node_modules/protractor/bin/webdriver-manager start",
"proupdate": "./node_modules/protractor/bin/webdriver-manager update"
}
you would then run these by typing npm run prostart or npm run proupdate which would look for those commands in your package.json.
In addition to Josh's answer, the script start could be run as npm start as start is a special keyword, but update should be run as npm run update because npm update is another npm command entirely.
For any other command besides start and test (I think), you have to preface it with npm run ...

Grunt.js Installation Issue - Command Not Found

I'm trying to get grunt.js set up on my work machine. Now I've managed to get it set up at home, so I pushed my repository, then cloned it on my work machine, however despite troubleshooting this to death I've always run into the same issue when I come to try and run the command on my work computer;
sh.exe": grunt: command not found
So some background and explanation;
I'm using Aptana 3.0 and running all my commands through the terminal. (This applies to my home and work computer)
I cloned the "working" repository and put it in a folder on my work machine, so I have my package.json and gruntfile.js files inside said directory. These work fine on my home computer and I am able to run the watch task set up in my gruntfile.js successfully at home.
I've run npm install grunt-cli -g and npm install inside my project on my WORK computer and installation has been successful each time. My only error messages on either are a lack of description and a repository field which, to my knowledge these aren't mandatory?
The node modules folder inside my repository indicates I have the following installed (as per my package.json)
grunt
grunt-contrib-compass
grunt-contrib-uglify
grunt-contrib-watch
matchdep
Now I'm pretty green to this command line stuff, so I may have overlooked something very obvious but I feel like I've tried every guide going to get this thing to work.
Despite running through the getting started steps/installing grunt documentation repeatedly, it seems no matter what I do the terminal will not pick up grunt as a recognized command.
Am I stupid or is this some other issue?
EDIT 1: contents of my package.json:
{
"name" : "xxxxxxxxx",
"version" : "xxxx",
"dependencies" : {
"grunt":"~0.4.1",
"grunt-contrib-watch": "~0.5.3",
"grunt-contrib-compass": "~0.5.0",
"grunt-contrib-uglify": "~0.2.2",
"matchdep": "~0.1.2"
}
}
This is happening because you are using the Aptana Terminal, which needs the PATH variable to work out what is meant by grunt etc. A normal cmd prompt would work fine with the command npm install grunt-cli -g but in this context the terminal is unaware of what grunt is.
As per the following existing answer, you need to set up your Windows PATH variable to make the Aptana Terminal aware of the npm directory: https://stackoverflow.com/a/19137584/463205
C:\Users\Username\AppData\Roaming\npm
Closing the terminal and reopening it after setting the PATH correctly should enable you to run the command successfully.
Try to run
npm install grunt-cli -g
On your home computer.
-g means - install Grunt globally (not in the project node_modules folder), so it'll add grunt command to the bin folder which is used by nodejs console ( and you need to run node.js command prompt, not just arbitrary cmd)

React - jsx --watch does nothing after first conversion

I can't use in browser JSXTransformer.js even for development, because i am using require.js for loading modules.
When i run jsx --watch src/ build/, actually just one jsx->js conversion is performed against files in src directory, but subsequently, if i change any file in src directory, nothing happened, no translation jsx->js (like if jsx --watch didn't noticed any changes).
Same happened to me.
Try this command line:
jsx --watch -x jsx src/ build/
I had the same problem, but this helped:
jsx --watch ./scr ./build
Actually it happens when you are trying to start the command from wrong folder or set the wrong path to folder from which you want to build (e.g. "src/"). Write path depends on you directory's structure. Best way to find out write path is to print the command "jsx --watch " and then use Tab to get path to directory you need or just make sure the current folder in terminal contains build/ and src/ folders.
I'm having the same issue, and maybe it's because I don't really understand how "--watch" is supposed to work. What I initial did was this: open terminal, punch in "watch" command (e.g. "jsx --watch /src /build). As soon as I did that, the terminal spit back something like "helloworld.js was built". All good.
Then I closed the terminal window and nothing worked after that.
Then I re-opened the terminal, re-typed the command, and the watch command worked.
Then I closed the terminal, and it stopped working.
I'm sensing a pattern here. Is the JSX watch command only active while the containing terminal window is open? I assumed "watch" was a "set it once and forget it" command, but it sounds like it's more ephemeral than that?
You have this issue probably bacause of the suffix of the files is jsx and not js the jsx command not recognize .jsx files.
You can do as user2038099 said:
jsx --watch -x jsx src/ build/
-x, --extension File extension to assume when resolving module identifiers
or you can change the suffix of the files in the src folder to .js.
https://github.com/facebook/react/issues/4269
I had this problem running Ubuntu 14.04. The jsx command would not give any feedback regardless what arguments I passed it. I eventually ended up uninstalling node entirely and installed using the instructions for Ubuntu at https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager
I was previously on nodejs v0.10.28, but now that I'm on nodejs v0.12.7 everything is working fine.

Categories

Resources