Why does npm run build for babel throw an error: "babel: src does not exist" - node.js

My folder is src and I've installed babel via the CLI, yet I'm still getting an error, "babel:
src does not exist"
Here's a quick recording of of my code: https://drive.google.com/file/d/1YgEnJE87c0mEnsefY1xU94cvUedBtGhK/view
See above what I've tried.
{
"name": "notes-app",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "babel src -d lib"
},
"author": "Jono Suave",
"license": "ISC",
"devDependencies": {
"#babel/cli": "^7.7.0",
"#babel/core": "^7.7.2"
}
}
app.js
import getNotes from "notes.js"
getNotes()
notes.js
let getNotes = function() {
console.log(`Put the time in baby!`)
}
module.exports = getNotes
I expected babel to run and compile my ES6 import code in app.js, but instead received following error in terminal:
babel:
src does not exist
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! notes-app#1.0.0 build: `babel src -d lib`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the notes-app#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! /Users/jonosuave/.npm/_logs/2019-11-07T01_56_26_260Z-debug.log

In experimental node, Babel isn't even required -- just need to use a .mjs extension to files instead of .js
See explanation with example: How can I use an es6 import in node?

Related

Getting missing script: start error in npm

I get this error when I run npm start.
npm ERR! Missing script: "start"
npm ERR! Did you mean one of these?
npm ERR! npm star # Mark your favorite packages
npm ERR! npm stars # View packages marked as favorites
npm ERR! To see a list of scripts, run:
npm ERR! npm run
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\USER\AppData\Local\npm-cache\_logs\2022-04-28T13_04_19_260Z-debug.log
package.json has various sections, scripts is one of them, which allows you to write npm scripts which we can run using npm run <script-name>. The error you're getting is because your start script is missing in that section.
For a node app, your package.json file should look similar to this.
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"start": "node app.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.20.0",
"cors": "^2.8.5",
"express": "^4.17.3"
}
}
In the above code, focus on the scripts section. The following line is missing in your package.json file.
"scripts": {
"start": "node app.js",
},
Add this line and you're good to go.
Option_1: Control inside file "package.json":
"scripts": {
"start": "what command is here?",
},
Option_2: Control Terminal (folder) where you write command OR open the responding terminal for your project: right-click
on the project name -> "Open in integrated Terminal"
You have to put what command you need npm to run when you give npm start.
You have to write node index.js in scripts.start in your package.json file

"node server.js" works, but "npm start"cannot find node

Answers to similar questions here and here do not resolve my issue.
In an empty directory I create a file 'server.js' all it does is a console.log('hello'). Running this file with "node server.js" runs fine. But after "npm init -y" running through "npm start" gives:
npm start
The system cannot find the path specified.
> prj#1.0.0 start E:\projects\prj
> node server.js
/bin/bash: node: command not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file bash
npm ERR! errno ENOENT
npm ERR! prj#1.0.0 start: `node server.js`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the prj#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?
The detailed logfile reports correct versions of npm and node. And all of this is after an uninstall/reinstall of node.js.
Any hints on how to troubleshoot/fix appreciated.
project directory:
E:\prj
package.json
package-lock.json
server.js
package.json is the default after npm init:
{
"name": "prj",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"keywords": [],
"author": "",
"license": "ISC"
}

I am unable to get the command that should help me in running the website on local host

Here is package.json
{
"name": "complete",
"version": "1.0.0",
"description": "Implemented an ethereum smart contract in Solidity to develop an online MarketPlace
where people can buy, sell products, ask for a refund, check transaction status etc. The client side
pages are served by a Flask server.",
"main": "truffle-config.js",
"directories": {
"test": "test"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
Here is the error
npm run test
> complete#1.0.0 test F:\complete
> echo "Error: no test specified" && exit 1
"Error: no test specified"
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! complete#1.0.0 test: `echo "Error: no test specified" && exit 1`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the complete#1.0.0 test 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\HP\AppData\Roaming\npm-cache\_logs\2020-02-04T08_30_37_917Z-debug.log
You must provide test command in the script field.
eg: I use mocha for testing
"scripts": {
"test": "mocha"
}

Using NPM for SCSS but the script will not watch for changes. It gives me a error

I have installed Node v12.10.0, NPM v6.10.3. I have also tried to install the node LTS version as well.
I built my project directory and inside the directory I ran "npm init" and after I ran "npm install --save-dev node-sass". Everything seems good up to this point.
my package.json file looks like this
{
"name": "dashboard",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"scss": "node-sass --watch scss -o css"
},
"author": "",
"license": "ISC",
"devDependencies": {
"node-sass": "^4.12.0"
}
}
After I go to run " npm run scss" then I receive this.
> dashboard#1.0.0 scss /Users/adakaitalker/Documents/school/dev/learning/2-september/4-week/9:13:19/dashboard
> node-sass --watch scss -o css
sh: node-sass: command not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! dashboard#1.0.0 scss: `node-sass --watch scss -o css`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the dashboard#1.0.0 scss 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/adakaitalker/.npm/_logs/2019-09-13T22_43_56_711Z-debug.log
figured it out. I installed homebrew and linked it to node then I used homebrew to uninstall it and reinstall it and it works now.

Getting "Assertion `args[1]->IsInt32()' failed" running npm start, no error when running node index.js instead

I have a package.json file set up with the following:
...,
"scripts": {
"start": "node index.js",
"test": "mocha"
},
...
So I'm trying to run it with npm start. Unfortunately, it's giving me the following error output:
npm[7444]: src\node_file.cc:1599: Assertion `args[1]->IsInt32()' failed.
1: 00007FF75D44121A v8::internal::GCIdleTimeHandler::GCIdleTimeHandler+4810
2: 00007FF75D41A5B6 node::MakeCallback+4518
3: 00007FF75D41A66F node::MakeCallback+4703
4: 00007FF75D3DF663 uv_loop_fork+34595
5: 00007FF75DC45782 v8::internal::OptimizingCompileDispatcher::Unblock+60562
6: 00007FF75DC46C1D v8::internal::OptimizingCompileDispatcher::Unblock+65837
7: 00007FF75DC45C79 v8::internal::OptimizingCompileDispatcher::Unblock+61833
8: 00007FF75DC45B5B v8::internal::OptimizingCompileDispatcher::Unblock+61547
9: 000002E4183DC5C1
npm ERR! code ELIFECYCLE
npm ERR! errno 134
npm ERR! c4sk#1.0.0 start: `node index.js`
npm ERR! Exit status 134
npm ERR!
npm ERR! Failed at the c4sk#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! C:\Users\Steven\AppData\Roaming\npm-cache\_logs\2019-01-11T04_52_55_255Z-debug.log
For reasons I cannot begin to fathom, this is only happening on one machine. Also, while npm start fails with this error, simply skipping npm and running node index.js works fine.
All machines have fresh installs of Node.js v10.15.0
What ... on earth?
In case it would help, here's my package.json:
{
"name": "c4sk",
"version": "1.0.0",
"description": /**/,
"main": "index.js",
"scripts": {
"start": "node index.js",
"test": "mocha"
},
"repository": {
"type": "git",
"url": "/**/"
},
"author": "Steven Kitzes",
"license": "ISC",
"bugs": {
"url": "/**/"
},
"homepage": "/**/",
"devDependencies": {
"mocha": "^5.2.0"
},
"dependencies": {
"readline-sync": "^1.4.9"
}
}
Update: I have traced the problem down to the readline-sync package (or perhaps one of its dependencies). I switched to another package for CLI input (the prompt package) and was able to get my application going. The next time I have access to my home machine I will update with the logs requested in the comments to see if we can get to the bottom of the issue with readline-sync.
Downgrade to node version 14. You can use nvm to manage node versions.

Resources