Lite-server not working - javascript

I had a project that was previously using lite-server. I can no longer get it to run using
npm run
I see the following from the console
PS C:\Users\XXX\Documents\Work\Repos\Homepage_Slider> npm run
Lifecycle scripts included in homepage_slider: test
echo "Error: no test specified" && exit 1 start
lite-server
I don't really understand why this isn't working anymore.
I've tried:
Updating NPM
Running lite-server globably
Make sure package.json is set up correctly
Here is my package.json file
{
"name": "homepage_slider",
"version": "1.0.0",
"description": "A simple slider for homepage",
"main": "index.html",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "lite-server"
},
"repository": {
"type": "git",
"url": "XXX"
},
"keywords": [
"Slider"
],
"author": "XXX",
"license": "ISC",
"devDependencies": {
"lite-server": "^2.3.0"
},
"dependencies": {
"npm": "^6.0.1"
}
}

npm run is a reserved word for npm itself. Check the documentation
What you really need is npm start which is a shortcut for npm run start which is a shortcut for npm run-script start!

Related

Getting references error when importing tone.js

I have a basic express.js server setup on my Mac. To this I'm trying to import Tone.js, https://tonejs.github.io, by following the instructions.
npm install tone
To import Tone.js:
import * as Tone from 'tone'
But I'm getting this error
Uncaught TypeError: Failed to resolve module specifier "tone". Relative references must start with either "/", "./", or "../".
My Package file looks like this
{
"name": "XXXXX",
"version": "1.0.0",
"description": "Run npm start",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon start"
},
"repository": {
"type": "git",
"url": "git+https://github.com/xxxxx"
},
"author": "xxxxx xxxx",
"license": "ISC",
"bugs": {
"url": "https://github.com/xxxxxxx"
},
"dependencies": {
"express": "^4.17.1",
"nodemon": "^2.0.12",
"tone": "^14.7.77"
}
}
As #lars-flieger pointed out, it's not possible to run it one a node.js server.
I ended up downloading Tones.js from here and includes it as a regular script tag.
https://github.com/Tonejs/Tone.js/wiki/Installation

NPM npm_package_main variable is always empty

Problem
NPM $npm_package_main variable is always empty.
When I set the package.json file with "main": "index.js"
Set the "start" property from scripts to "start": "node $npm_package_main"
Then run npm start
Problem: the CLI executes the Node REPL mode, ignoring the "main" variable from package.json.
Expected behavior: execute the command as node index.js.
Environment
Linux Ubuntu 20.04.1
npm -v = 7.3.0
node -v = v15.5.0
npm run env | grep npm_package_name = npm_package_name=app
npm run env | grep npm_package_main = EMPTY
How to reproduce
Create an "app" directory and enter the new directory
Create an "index.js" file with the following content
console.log('HELLO');
Run npm init and hit ENTER for all questions
Edit the package.json file and add the following line to the "scripts" property:
"start": "node $npm_package_main",
now your package.json must look like this
{
"name": "app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"devDependencies": {},
"scripts": {
"start": "node $npm_package_main",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
Run "npm start"
File "index.js" is not executed and Node enters the REPL mode.
Attempts
Set "start" and running "npm start" for:
"echo $npm_package_main" prints nothing
"echo $npm_package_name" prints "app"
"echo $npm_package_version" prints "1.0.0"
References
NPM package.json variables: https://docs.npmjs.com/cli/v7/using-npm/scripts
NPM Github issue: https://github.com/npm/cli/issues/2585
The official answer from NPM: use "node .". There's no official reason for this behavior, until this post.
According to the documentation, the "main" property contains the entrypoint for your app when is used as a module in other projects: https://docs.npmjs.com/cli/v7/configuring-npm/package-json#main
Solution
Use the "config" property instead:
{
"name": "app",
"version": "1.0.0",
"description": "",
"devDependencies": {},
"config": {
"main": "index.js"
},
"scripts": {
"start": "node $npm_package_config_main",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
Run "npm start"
It works
References:
https://github.com/npm/cli/issues/2585
https://github.com/npm/cli/pull/2446

My node-sass npm script is not compiling

The structure of my project looks like this:
And my package.json looks like this:
{
"name": "personal_site",
"version": "1.0.0",
"description": "My personal website.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "node-sass --output-style compressed ./dist/css/bundle.min.css ./src/scss/styles.scss",
"serve": ""
},
"author": "Dean Gibson",
"license": "ISC",
"dependencies": {
"bourbon": "^4.2.6",
"bourbon-neat": "^1.7.4"
},
"devDependencies": {
"node-sass": "^3.4.2"
}
}
But when I run npm build it looks like the terminal is "thinking" and it stops without throwing any errors. But nothing gets generated in dist/css/ ... Anything obvious that I'm doing wrong here?
UPDATE:
This is interesting, if I run that exact script directly from terminal then it works fine... Any ideas as to why?

How to set npm run dev as starter for your app?

I am working with React and I am trying to figure out how to set npm run dev in order to compile and put my app to work. Right now, I need to do this in the terminal in order to see my app running
$ node server/index.js
here is the way I have my folders
and here is what I have in package.json
{
"name": "iOS.server2x.socket",
"version": "0.0.1",
"description": "iOS Live Socket.",
"author": "iOS Interactive",
"main": "server/index.js",
"port": 1101,
"scripts": {
"pretest": "eslint ./server",
"test": "echo \"Error: no test specified\" && exit 0",
"start": "rm -rf /home/git/.forever/chat.log; forever start --uid 'chat' ./server/index.js",
"stop": "forever stop chat"
},
"repository": {
"type": "xxxxxx",
"url": "http://url/url"
},
"dependencies": {
"async": "^1.4.2",
"babel": "5.8.3",
},
"devDependencies": {
"babel-eslint": "4.0.5",
}
}
And also, should I need webpack for this ?
I will answer my own question:
there is a way to set this actually, all I did is in the package.json in the scripts part
"scripts": {
"dev": "nodemon ./server/index.js",
"pretest": "eslint ./server",
"test": "echo \"Error: no test specified\" && exit 0",
"start": "rm -rf /home/git/.forever/chat.log; forever start --uid 'chat' ./server/index.js",
"stop": "forever stop chat"
}
so, npm run <here something in that json>, like
$ npm run dev in order to start the server
$ npm run pretest this is the task to run eslint
and so on . . .

node_modules is not recognized as an internal or external command

I'm trying to write a test automation script using appium, jasmine, and perfecto mobile. I'm using the project cloned from the following URL with my own configuration Appium Javascript Example
The problem is when I execute the npm test command I get the following error
node_modules is not recognized as an internal or external command
This is how the packages.json script looks like:
{
"name": "perfecto_appium_sample",
"version": "1.0.0",
"description": "The following sample shows how to Install an application and use WebDriverIO to automate and test it.<br/> It uses selendroid test application which can be downloaded from [here](https://github.com/PerfectoCode/AppsForSamples/tree/master/selendroid-test-app-0.17.0).",
"main": "perfectoSpec.js",
"scripts": {
"test": "node_modules/webdriverio/bin/wdio wdio.conf.js",
"start": "wdio wdio.conf.js"
},
"author": "",
"license": "ISC",
"devDependencies": {
"wdio": "^0.3.3",
"wdio-jasmine-framework": "^0.2.19",
"wdio-mocha-framework": "^0.5.12"
},
"dependencies": {
"wd": "^1.5.0",
"webdriverio": "^4.10.2"
},
"keywords": []
}
you need to provide relative path properly:
"scripts": {
"test": "node ./node_modules/webdriverio/bin/wdio wdio.conf.js",
"start": "wdio wdio.conf.js"
}
Just remove the paths "node_modules/webdriverio/bin/" and simply specify "wdio wdio.conf.js". It should work.

Categories

Resources