Npm ERR! Line breaks can’t be quoted on Windows - node.js

i have the following package.json code:
{
"name": "pre-post",
"version": "1.0.0",
"description": "",
"main": "basic-server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"ignore": "echo \"\" >> .gitignore",
"preignore": "touch .gitignore",
"postignore": "echo \".gitignore\n.vscode/\nnode_modules/\" >> .gitignore"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"linebreak": "^1.0.2",
"open": "^7.4.0"
}
}
after i run in node js command, i have the error message of npm ERR! Line breaks can't be quoted on Windows, any fix?

Check whether your package.json have swiper
There are 4 steps to solve this problem
Remove "swiper" : "^5.4.5" from package.json file.(Check there should be no comma in last line of your json file)
Run npm install command in your terminal.
Run npm install swiper command.
Now you will see everything has been installed successfully.

Just don't install it from Git Bash on Windows. Use cmd.exe and it works as a charm !

Uninstall node.js from Control Panel/Programs
Download fresh node.js installer and install them.
(important) reboot system.

I face the same problem and this thing is work for me
Uninstall node completely use this answer
reboot your device
download again from official website

Use yarn to install the dependencies. Solved for me.

Related

NPM preinstall script

I am trying to run some policing script before any packages are installed.
For Example:
{
"name": "pre-hook-check",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"preinstall": "echo preinstall",
"postinstall": "echo postinstall"
},
"author": "",
"license": "ISC",
"dependencies": {
"abc": "^0.6.1",
"preact": "^8.2.5"
}
}
It seems the pre and post install script on above example only works when I do npm install, but I want that to run every time I try to install anything.
For example: Let's say I want to write a script to check for the version of the package any time my team runs npm install <some package>. I want to check for the version of installing package and verify that it's version is above "1.0.0" else don't let them install.
I was planning to write a preinstall script that goes
npm info lodash version
and checks for the version of any package I am trying to install. If the version is not available, I plan to make it interactive and ask user's acknowledgement before install.
You are right the preinstall script runs only when we do npm install and there is currently no way to run a script before installing a module but you can use shell scripting and npm view
https://docs.npmjs.com/cli/view to do so .
First , create a moduleinstall.sh file which has the same scope as your package.json and the below shell script to it
echo 'Enter the name of the module'
read module_name
npm view $module_name version
echo "Do you want to install this version(y/N) "
read option
if [ "$option" = "N" ] || [ "$option" = "n" ]
then
echo "exiting...."
exit 1
else
npm install $module_name
fi
make sure you make it executable using chmod +x moduleinstall.sh and then write this in your package.json
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"info": "./moduleinstall.sh"
}
Now you just have to run the command npm run info and then follow the instruction to install a module by checking the version . You can advance it using different options of npm view and shell scripting.
Hope this helps.

can not setup ReactJS on mac

I need to setup ReactJS on my Mac. I have npm version of 4.1.2 and node version of v7.7.4. I clone the project from Git and in the project folder trying to execute npm install and following npm start. But I get error.
I removed&uninstalled node and npm and then re-installed with homebrew, but it did not help. Here is the screen of error I get in terminal? Do you have any idea what is the problem?
Here is my package.json file
{
"name": "viaopt",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {},
"devDependencies": {
"webpack": "^2.3.0"
},
"description": ""
}
From the error you are showing I can tell that there is no start script in your package.json file. For npm start to work there should be a command under the start key under the scripts attribute in your package.json file.
When you run npm start npm looks in package.json and runs whatever is listed there under the start value.
I'm guessing you have gulp or webpack configured with your project?
Try running webpack in your terminal and see if your project fires up or smth.
Hopes this helps.
Cheers.
If your trying to setup a new React App you can use
Create React App. It will setup React / Webpack for you.

Refusing to install 'module' as a dependency of itself

Recently, I was playing with a gulp tutorial and had this error
Refusing to install gulp as a dependency of itself
when executing
npm install --save-dev gulp
what could be the issue?
The problem was in the name of my own application.
In package.json, I accidently named it gulp
{
"name": "gulp",
"version": "1.0.0",
"description": "tutorial",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "rmv",
"license": "ISC",
"devDependencies": {}
}
Make sure your app is not called as one of the dependencies you will be using.
This error occurs when you are trying to install the package from the path (or in the folder) in which you had created the package.. Just navigate to some other folder or path and then try to install the package It should work.

npm looks like does not generate the correct wrapper for cli (nodejs)

I use Windows 10, node 5.3.0 and npm 3.5.2
I did a cli, a simple hello world. This is its package of the module
{
"name": "helloworld",
"version": "1.0.0",
"bin": {"hellow": "hello.js"},
"preferGlobal": true,
"description": "Hello...",
"main": "hello.js",
"scripts": {
"test": "node hello.js"
},
"keywords": [
"testing"
],
"author": "me",
"license": "ISC"
}
The test works ok, and I install the module from its directory
npm install -g helloworld
When I execute 'hellow' appears its path and Windows asks me how to open the file.
npm wrappers are like this, from node_modules directory
"%~dp0\node_modules\helloworld\hello.js" %*
I don't know what is going wrong. Thanks.
Ok, I solved it doing more investigation
This is a good guide of how to make a complete npm package http://www.anupshinde.com/posts/how-to-create-nodejs-npm-package/
besides you need to add this line at the beginning of the bin script
#!/usr/bin/env node
So, this is already done (and I am glad =) )

how to automate dependency resolution (local and remote) in node

I have a very small data-cap so I want to install dependencies for node projects by first linking to whatever it finds installed on local machine and fetching remotely if not found locally. I don't want to manually go through all the require statements in the apps because theres a lot of them - is there a node way to do this?
eg. this except not manually determining what is or isn't installed
Project A
npm install -g connect
npm install -g serve-static
then later
Project B
npm link connect
npm link serve-static
The preferred way to go about dependency management is with a package.json.
To get started with one of these in a project, run npm init, and answer all the questions. This will leave you with a file like this:
{
"name": "test-project",
"version": "1.0.0",
"description": "A test project",
"main": "test.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Josh",
"license": "ISC"
}
Once this is in place, add the --save flag to each of your npm install commands. For example, if you run npm install --save connect, your package.json changes to this
{
"name": "test-project",
"version": "1.0.0",
"description": "A test project",
"main": "test.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Josh",
"license": "ISC",
"dependencies": {
"connect": "^3.3.5"
}
}
Now whenever you need to install the project's dependencies, run npm install, and all the dependencies listed in the package.json will be automatically installed.

Resources