can't run "npm start" - javascript

this is my package.json file:
{
"name": "martina",
"version": "1.0.0",
"description": "d",
"main": "index.js",
"scripts": {
"start": "node index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "d"
},
"author": "",
"license": "ISC"
}
what should I do? I have a Mac by the way!
EDIT: I did what you guys recommended and added the script start, but now when I run 'npm start' I get this:
> martina#1.0.0 start /Users/martina
> node index.js
internal/modules/cjs/loader.js:589
throw err;
^
Error: Cannot find module '/Users/martina/index.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:587:15)
at Function.Module._load (internal/modules/cjs/loader.js:513:25)
at Function.Module.runMain (internal/modules/cjs/loader.js:760:12)
at startup (internal/bootstrap/node.js:303:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:872:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! martina#1.0.0 start: `node index.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the martina#1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/martina/.npm/_logs/2020-06-11T08_05_28_654Z-debug.log

You need to add a start script under scripts, and to host or start the application on local node server, add the command node index.js as the value for start script.
{
"name": "martina",
"version": "1.0.0",
"description": "d",
"main": "index.js",
"scripts": {
"start": "node index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "d"
},
"author": "",
"license": "ISC"
}
PS: While running the command npm start, make sure that you are in the correct project directory. The file index.js and package.json needs to be present as the direct childs of this project directory.
Project Structure:
martina
|- index.js
|- package.json
|- file1
|- file2
|- ...other files
...
See in the above project structure, martina is the main project directory. And inside martina, index.js and package.json can be found.

You need to add a start script under scripts, i.e.:
{
"name": "martina",
"version": "1.0.0",
"description": "d",
"main": "index.js",
"scripts": {
"start": "echo STARTING...",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "d"
},
"author": "",
"license": "ISC"
}
Try npm run test to get an idea of how the scripts field works for package.json.

{
"name": "martina",
"version": "1.0.0",
"description": "d",
"main": "index.js",
"scripts": {
"start": "node index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "d"
},
"author": "",
"license": "ISC"
}
Your package appears by looking at the file. That you have just created the project. It seems that the directory of your index.js file in not correct. you create the index.js file in the package.json directory itself, after that run the node index.js or npm start command
> martina#1.0.0 start /Users/martina
> node index.js
internal/modules/cjs/loader.js:589
throw err;
^
Error: Cannot find module '/Users/martina/index.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:587:15)
at Function.Module._load (internal/modules/cjs/loader.js:513:25)
at Function.Module.runMain (internal/modules/cjs/loader.js:760:12)
at startup (internal/bootstrap/node.js:303:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:872:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! martina#1.0.0 start: `node index.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the martina#1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/martina/.npm/_logs/2020-06-11T08_05_28_654Z-debug.log
Try this one. Your solution will be done. If you still get an error then let me know

Related

npm install lite-server --save-dev installation error

I am trying to use node for the first time,installed node.js below is the information
node -v
v14.4.0
npm -v
6.14.5
Completed the setup by creating a package.json file, then tried to install lite-server using the command
npm install lite-server --save-dev produced the folllowing error:
npm WARN deprecated chokidar#2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
npm ERR! cb() never called!
npm ERR! This is an error with npm itself. Please report this error at:
npm ERR! <https://npm.community>
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\ojhaa\AppData\Roaming\npm-cache\_logs\2020-06-06T06_54_54_480Z-debug.log
Followed by
npm cache clean --force
Here is the package.json file
{
"name": "git-test",
"version": "1.0.0",
"description": "\"This is a test directory to learn git and node\"",
"main": "index.html",
"scripts": {
"start": "npm run lite",
"test": "echo \"Error: no test specified\" && exit 1",
"lite": "lite-server"
},
"repository": {
"type": "git",
"url": "git+https://github.com/apoorva0212/git-test.git"
},
"author": "\"Apoorva Ojha\"",
"license": "ISC",
"bugs": {
"url": "https://github.com/apoorva0212/git-test/issues"
},
"homepage": "https://github.com/apoorva0212/git-test#readme"
}
But still I get the same error. Can anyone help me with this?
Thank you, in advance.
you are missing the dependency on lite-server
try to install lite-server dependency
npm install lite-server --save-dev
then invoke npm run lite

"concurrently command not found" but installed gloabally

I'm using macOs and even though concurrently is installed globally through npm, when setting it as a start script in package.json and typing npm start the following error occurs.
concurrently - kill-others "npm run server" "npm run client"
sh: concurrently - kill-others: command not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! thesis_fullstack#1.0.0 start: `concurrently - kill-others "npm run server" "npm run client"`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the thesis_fullstack#1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/mantzaris/.npm/_logs/2020-04-25T22_40_12_897Z-debug.log
My package.json file :
{
"name": "thesis_fullstack",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"client": "cd client && npm start",
"server": "cd server && npm start",
"start": "concurrently - kill-others \"npm run server\" \"npm run client\""
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"concurrently": "3.5.1"
}
}
You need to install the dependency locally in order to use it in any of your start scripts. run
npm install --save concurrently
to install it locally in your project
Your error is not with the package itself, you can either have it globally or save it locally (not --save-dev).
You can find the solution for your problem looking at the error log
concurrently - kill-others "npm run server" "npm run client"
sh: concurrently - kill-others: command not found
The command should be either --kill-others or -k for short, here is the official documentation: https://github.com/kimmobrunfeldt/concurrently
Try this as your package.json
{
"name": "thesis_fullstack",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"client": "cd client && npm start",
"server": "cd server && npm start",
"start": "concurrently --kill-others \"npm run server\" \"npm run client\""
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"concurrently": "3.5.1"
}
}
Cheers :)
I seriously don't know what I did to fix it. First of all i fixed the command flag "typo" to concurrently --kill-others your_commands_here. Then i uninstalled node manually and reinstalled it through Homebrew (since I'm using MacOs). After that node and npm wouldn't work at all. Fixed it with: https://stackoverflow.com/a/54583099/13212764. I think by that point running npm start worked.
For
Globally -
npm install -g concurrently
Locally -
npm install concurrently

How to run ts script with package.json?

I try to run typescript files with just a package.json file. So a minimum setup for running typescript files.
I just have a singel file: index.ts:
console.clear();
console.log("nic to see you!!");
and package.json file:
{
"name": "Todo",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js"
},
"keywords": [],
"author": "",
"license": "ISC"
}
But if I try to do :
npm start, I will get this error:
Error: Cannot find module 'D:\Mijn Documents\UDEMY\TypeScript\Todo\index.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! Todo#1.0.0 start: `node index.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the Todo#1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\User.USER-PC\AppData\Roaming\npm-cache\_logs\2019-12-24T11_22_12_024Z-debug.log
PS D:\Mijn Documents\UDEMY\TypeScript\Todo>
So my question is: what I have to change that it will compile?
Thank you
oke, I have it now like this:
packagege.json:
{
"name": "Todo",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build":"tsc -p ./src",
"start": "npm run build -- -w"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"ts-node": "^8.5.4",
"typescript": "^3.7.4"
}
}
And I installed typescript
and I do: npm start. I still get this error:
npm run build -- -w
> Todo#1.0.0 build D:\Mijn Documents\UDEMY\TypeScript\Todo
> tsc -p ./src "-w"
error TS5057: Cannot find a tsconfig.json file at the specified directory: './src'.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! Todo#1.0.0 build: `tsc -p ./src "-w"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the Todo#1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\User.USER-PC\AppData\Roaming\npm-cache\_logs\2019-12-24T11_33_38_340Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! Todo#1.0.0 start: `npm run build -- -w`
npm ERR! Exit status 1
oke, I have it now like this:
{
"name": "Todo",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "tsc main.ts dist/",
"start": "npm run build -- -w"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"ts-node": "^8.5.4",
"typescript": "^3.7.4"
}
}
and if I do this: npm run. I see this output:
> Todo#1.0.0 build D:\Mijn Documents\UDEMY\TypeScript\Todo
> tsc main.ts dist/ "-w"
[1:46:58 PM] Starting compilation in watch mode...
error TS6053: File 'dist/.ts' not found.
[1:46:59 PM] Found 1 error. Watching for file changes.
oke, I see now this:
> Todo#1.0.0 build D:\Mijn Documents\UDEMY\TypeScript\Todo
> tsc -p ./ "-w"
[2:00:31 PM] Starting compilation in watch mode...
[2:00:34 PM] Found 0 errors. Watching for file changes.
But where I can see the results then? Will be nice to go to some port, like: localhost:4200 in the browser, but how to do that?
Try typing in the terminal as follows:
ts-node ./src/index.ts
Or, try the following modifications to the "start" script:
"start": "ts-node ./src/index.ts"
Thank you all!!
the trick was this in the package.json:
"start": "tsc-watch --onsuccess \"node dist/index.js\""

npm run script error on windows

I am using webpack to build my app so I am getting the following error on command prompt:
forkify#1.0.0 dev D:\Myprograms\java script\forkify
webpack --mode development
Insufficient number of arguments or no entry found.
Alternatively, run 'webpack(-cli) --help' for usage info.
Hash: 750054014bbd689a84a8
Version: webpack 4.16.5
Time: 85ms
Built at: 2018-08-07 10:22:56
ERROR in Entry module not found: Error: Can't resolve './scr/js/index.js' in 'D:\Myprograms\java script\forkify'
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! forkify#1.0.0 dev: webpack --mode development
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the forkify#1.0.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Acer\AppData\Roaming\npm-cache_logs\2018-08-07T04_52_57_041Z-debug.log
My webpack.config.js is as follows:
const path = require('path');
module.exports = {
entry: './scr/js/index.js',
output: {
path: path.resolve(__dirname,'dist/js'),
filename: 'bundle.js'
}
};
My package.json file as follows:
{
"name": "forkify",
"version": "1.0.0",
"description": "forkify project",
"main": "index.js",
"scripts": {
"dev": "webpack --mode development",
"build": "webpack --mode production"
},
"author": "abhilash narayan",
"license": "ISC",
"devDependencies": {
"webpack": "^4.16.5",
"webpack-cli": "^3.1.0"
}
}
Also check the screen shots
My file structure webpack.conifg.js:
It looks to me like a spelling mistake, entry: './scr/js/index.js
try to change it to ./src/js/index.js

Error while installing npm install grunt-contrib-clean --dev-save

Here is the package.json file
{
"name": "gruntTutorial.js",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"grunt": "^0.4.5"
"grunt-contrib-clean":"^0.5.0"
}
}
Having this package.json file, while installing npm install grunt-contrib-clean --dev-save I am getting below error.
C:\Users\prasad\Office\grunt>npm install grunt-contrib-clean --dev-save
C:\Users\prasad\Office\grunt
└── grunt-contrib-clean#0.7.0
npm WARN EJSONPARSE Failed to parse json
npm WARN EJSONPARSE Unexpected token 'g' at 13:6
npm WARN EJSONPARSE "grunt-contrib-clean":"^0.5.0"
npm WARN EJSONPARSE ^
npm WARN EPACKAGEJSON grunt No description
npm WARN EPACKAGEJSON grunt No repository field.
npm WARN EPACKAGEJSON grunt No README data
npm WARN EPACKAGEJSON grunt No license field.
Your package.json file doesn't parse because you're missing a comma at the end of
"grunt": "^0.4.5"
Also, the option is --save-dev not --dev-save.

Categories