"npm run build" = "react-scripts: Permission denied" - node.js

I'm trying to deploy my working Windows 10 Spring-Boot/React app on Ubuntu 18.04 but keep getting "react-scripts: Permission denied" error despite numerous attempts to fix. Hopefully one of you react experts can spot what I'm doing wrong.
My package.json looks like this
{
"name": "medaverter-front",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^4.2.4",
"#testing-library/react": "^9.3.2",
"#testing-library/user-event": "^7.1.2",
"axios": "^0.19.2",
"bootstrap": "^4.4.1",
"react": "^16.13.0",
"react-dom": "^16.13.0",
"react-router-dom": "^5.1.2",
"react-scripts": "3.4.0",
"react-table-6": "^6.11.0",
"react-validation": "^3.0.7",
"reactstrap": "^6.5.0",
"validator": "^12.2.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
I'm logged in as root and used nvm to install node and lts. I installed nvm like this:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash
then did this:
nvm install node
nvm use node
nvm install --lts
nvm use --lts
Then I cd to /var/lib/jenkins/workspace/MedAverter/medaverter-front and install node_modules like this:
npm install -g
and then change the permissions to 777 recursively, like this:
chmod -R 777 node_modules
I also changed all the /root/.nvm permissions to 777 recursively, like this:
chmod -R 777 /root/.nvm
I can get it build once using
npm run build
but then I run a "Build Now" from Jenkins and it fails with the same
[[1;34mINFO[m] Running 'npm run build' in /var/lib/jenkins/workspace/MedAverter/medaverter-front
[[1;34mINFO[m] [[1;34mINFO[m] > medaverter-front#0.1.0 build /var/lib/jenkins/workspace/MedAverter/medaverter-front
[[1;34mINFO[m] > react-scripts build [[1;34mINFO[m]
[[1;31mERROR[m] sh: 1: **react-scripts: Permission denied**
[[1;31mERROR[m] npm ERR! code ELIFECYCLE
[[1;31mERROR[m] npm ERR! errno 126
[[1;31mERROR[m] npm ERR! medaverter-front#0.1.0 build: `react-scripts build`
[[1;31mERROR[m] npm ERR! Exit status 126
Then I cd to /var/lib/jenkins/workspace/MedAverter/medaverter-front and run
npm run build
And also get the same error again:
> root#ubuntu-s-1vcpu-1gb-nyc1-01:/var/lib/jenkins/workspace/MedAverter/medaverter-front#
> npm run build
>
> > medaverter-front#0.1.0 build /var/lib/jenkins/workspace/MedAverter/medaverter-front
> > react-scripts build
>
> sh: 1: **react-scripts: Permission denied** npm ERR! code ELIFECYCLE
> npm ERR! errno 126 npm ERR! medaverter-front#0.1.0 build:
> `react-scripts build` npm ERR! Exit status 126
I've literally spent days trying to figure this out. Suggestions?

Solution 1:
I think you have react-script globally installed. so try this command
npm install react-scripts --save
and then run the application again.
Solution 2:
try this command
sudo chmod +x node_modules/.bin/react-scripts
and then run the application again.
Solution 3;
I think your npm not have permission. you can try to run by sudo
sudo npm run build
and you can fix this problem like this
Step 1:
check path of npm if you are using npm by
which npm
you will "/usr/local/bin/npm" this type of path
OR
check path of yarn if you are using yarn by
which yarn
you will "/usr/local/bin/npm" this type of path
Step 2:
give permission 777 to this path and try to run project
sudo chmod -R 777 /usr/local/bin/npm

Solution for macOS
From the root of your project run:
chmod +x node_modules/.bin/react-scripts

Instead of the default "start": "react-scripts start" specified in your package.json file, try changing it to the following and then try: "scripts": { "start": "node ./node_modules/react-scripts/bin/react-scripts.js start" }

I had modified the permissions on the folders earlier and undid the changes. I believe that is it.
I just deleted the node_modules folder and reinstalled the dependencies with the yarn command.
sudo rm -rf node_modules
yarn
yarn start

In my case it was giving at npm run.
this is how i solved.
rm -rf /node_modules
npm i
npm run android

It seems you don't have the right permission to build or execute the react app,
What you could do is try changing the owner to the current user using
sudo chown -R username:username /var/lib/jenkins/workspace/MedAverter/medaverter-front/
you can check your username by typing whoami in the terminal this is done because the current user does not have access to to the var folder or anything inside it by default. Furthermore you want to change the access mode to read and execute for everyone using
sudo chmod 755 /var/lib/jenkins/workspace/MedAverter/medaverter-front/
then you can want to change to root user using
sudo su
and then build the app using
npm run build
This has worked for me when i was facing somewhat a similar problem , hopefully it works for you as well,Cheers :)

I finally figured out a solution to this problem. It took days of effort. First, I deleted the Jenkins project and created a new one using Pipeline, rather than Freestyle. Then I added a Jenkinsfile with a script. That continued to fail but now I had the flexibility to add in additional commands to handle the errors.
One new error was something about jest-worker. I ran the following command on the DigitalOcean server to get past that one:
yarn add jest-worker
Then I had the old permissions error again. I think all these permission errors are due to user jenkins trying to run things owned by user root, even though everything had 777 permissions. I don't understand that but here's how I got around it. Modify the /etc/sudoers file and add the following line:
jenkins ALL=(ALL) NOPASSWD:ALL
Then modify the Jenkins file script to include recursive chmod and chown. Here is the full script that FINALLY worked:
pipeline {
agent any
stages {
stage('Checkout') {
steps {
echo 'Checkout...'
sh 'sudo chmod -R 777 /var/lib/jenkins/workspace/MedAverter/medaverter-front'
checkout scm
sh 'sudo chmod -R 777 /var/lib/jenkins/workspace/MedAverter/medaverter-front'
sh 'sudo chown -R jenkins /var/lib/jenkins/workspace/MedAverter/medaverter-front'
stash 'sources'
}
}
stage('Build') {
steps {
echo 'Build...'
unstash 'sources'
sh 'sudo chmod -R 777 /var/lib/jenkins/workspace/MedAverter/medaverter-front'
sh 'sudo chown -R jenkins /var/lib/jenkins/workspace/MedAverter/medaverter-front'
sh 'mvn clean package -DskipTests'
stash 'sources'
}
}
}
}
I also had to increase the memory of the DigitalOcean droplet from 1GB to 2GB to get past another error. If someone knows a better way to get past that frustrating permissions error, please comment.

That happens because of lack of a package.json file
Just run this command and the issue will be fixed:
npm audit fix

Sometimes npm need root permission. Try using sudo in the command. It resolved a similar issue for me. This might help.
sudo npm run build

I have the same issue and I sole it with: version in package.json and npm i -g react-scripts
"react-scripts": "5.0.0"
It was : "react-scripts": "5.0.1" and I change it to "react-scripts": "5.0.0"
And again did npm i
If it's not solving issue please check versions of react-scripts form current version of React that you are using.

The following worked for me:
rm -rf node_modules
npm install // or yarn install
npm start // or yarn start

Related

sh: husky: command not found

I've setup a node project with husky but when my collegue tries to run npm install on his Mac he gets the following error :
noa-be#1.0.0 prepare
husky install
sh: husky: command not found
npm ERR! code 127
npm ERR! path /Users/X/Desktop/Workspace/project
npm ERR! command failed
npm ERR! command sh -c husky install
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/X/.npm/_logs/2021-04-12T13_07_25_842Z-debug.log
These are the relevant package.json parts:
{
"scripts": {
"prepare": "husky install"
},
"devDependencies": {
"husky": "^5.2.0",
}
}
I thought this would be enough for husky to be installed when running npm install, but it's not. What am I missing?
If you are using nvm, you might want to create a file called .huskyrc in your home directory and add the following lines of code to it:
~/.huskyrc
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
I was struggling with the same exact problem for hours. Finally, I could install dependencies and start working on my project by doing this:
Temporarily remove the "prepare": "husky install" script from the package.json file.
Run npm i (npm install). Dependencies installed successfuly.
Add again the "prepare" script that you removed in step 1.
Run again npm i to install the husky git hooks, so husky can do its job from now on.
This error is also thrown by npm ci if the NODE_ENV is set to "production" pre-install
I've been able to solve the problem by upgrading to latest Husky version (7.0.1, from 5.2.0).
Git was also helpful, and told me that the files weren't executables. (Git V 2.24.1)
So I give them executable rights :
chmod +x PATH_TO_HUSKY_FILE
You'll need to execute this command for every hooks
I believe it could be version specific issue. Install version 6, npm i husky#6.0.0 --save-dev, and it should work as the husky doc says.
Apparently, when I did npm i husky --save-dev, it was installing "husky": "^0.8.1" for me for some strange reason, giving me the exact same error: sh: husky: command not found.
Method 1:
Update manually, in your package.json:
{
"scripts": {
"prepare": "husky install",
"create-hook": "husky add .husky/pre-commit \"npm test\"",
}
}
Then, run npm run prepare && npm run create-hook.
It should create .husky directory with .pre-commit file in it.
Method 2:
npx husky install
npm set-script prepare "husky install"
npx husky add .husky/pre-commit "npm test"
It worked in my terminal but not in VSCode version control. So had to force quite the vscode app and restarting it worked.
Faced this issue in Github Desktop.
solved it by quit Github Desktop and re-open it.
I was able to fix this by providing an explicit location for husky
"scripts": {
"prepare": "node_modules/.bin/husky-run install"
},
Using Lerna
When I upgraded husky from version 4 to 8 there was information todo first pre commit manually. For this purpose pre-commit bash script was generated in .husky directory.
What I had todo was simply run the command included in this file:
lerna run precommit --concurrency 2 --stream

created symlink using npm install on the vagrant machine which is hosted on centos7 but facing issues during buid from package

I was trying to install and build a project from package.json using npm. And it is a vagrant machine with centos7. I faced issues with npm install due to symlinks so used npm install --no-bin-links and packages got installed but later faced an issue during build using command sudo npm run build where my package.json file has
"start": "react-app-rewired start",
"build": "react-app-rewired --max_old_space_size=16384 build",
and the error is react-app-rewired command not found . Going through some suggestions on google added the below line to vagrant file
v.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate//", "1"]
The symlinks are created under the .bin folder in the node_modules folder when I ran npm install
but now when I ran sudo npm run build I get the below error
sh: /home/vagrant/UI/node_modules/.bin/react-app-rewired: Permission denied
when I check permissions on the folder .bin using ls -ld .bin following are the permissions
drwxrwxrwx. 1 vagrant vagrant 524288 Oct 19 13:22 node_modules
And when I check to see permissions using ls-l react-app-rewired on react-app-rewired following are the permissions
lrw-rw-rw-. 1 vagrant vagrant 0 Oct 19 13:22 react-app-rewired -> ../react-app-rewired/bin/index.js
can you help me in building the package.json file.
Fixed the issue by making changes to package.json. I replaced react-app-rewired in scripts with node ./node_modules/react-app-rewired/bin/index.js and react-scripts with node ./node_modules/react-scripts/bin/react-scripts.js

create-react-app + npm start - 'react-scripts' is not recognized as an internal or external command

Similar questions that I have tried following
"npm-run-all" is not recognized as an internal or external command
"'react-scripts' is not recognized as an internal or external command"
I am trying to create a React project via the create-react-app cli, but after creating the project I get the error
'react-scripts' is not recognized as an internal or external command, operable program or batch file"
when I try to launch the dev server via npm start.
What I have tried:
1) Make sure Node and npm are installed and up to date. From the project directory I run (via powershell)
> npm -v
6.7.0
> node -v
v11.11.0
2) Ensure that 'react-scripts' is listed with the correct version number in package.json
"name": "clipd2",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.8.4",
"react-dom": "^16.8.4",
"react-scripts": "^2.1.5"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
}...
3) Delete node_modules folder and package-lock.json and reinstall npm packages
rm -r -fo node_modules
rm package-lock.json
npm install
npm install -S react-scripts
After instalation the react-scripts directory is found (and populated) in node_modules
4) Make sure npm is in the environment PATH variable
> echo $Env:Path
....C:\Users\notMyUsername\AppData\Roaming\npm
I am at a loss for next steps. Strangely enough, I have another React app housed in the same parent directory
clipdReact
clipd
clipd2
And there are no problems when using npm start in the clipd project (whereas the failing project is clipd2)
Any suggestions or tips would be greatly appreciated!
**UPDATE
This bug was filed but is still open
react-scripts is not recognized
You can start the dev server (from your project's directory) with
.\node_modules\.bin\react-scripts start
Be careful generating the production build with a command similar to the one above - I had problems with babel and polyfills when trying to do so.
What worked for me in the end, was setting the script shell to powershell. The command for that is npm config set script-shell powershell and npm config delete script-shell to reset the config. I'm not sure why that worked, my guess is that since there are always 3 script files in node_modules\.bin that somehow the wrong shell was used for the wrong script or something like that.
npm install react-scripts --save --force

cross-env/dist/index.js:42 unexpected token }

A little background: I'm developing a Laravel 5 application. I'm developing locally on Windows 7 using Homestead (using Vagrant/VirtualBox) and deploying to an Amazon EC2 instance through CodePipeline.
While trying to get Laravel Mix working locally, I kept running into a cacophony of errors that eventually led me to the solution of installing cross-env globally rather than including it in the devDependencies in package.json. Of course, this also means that my Amazon deployment needed to be updated to that setup as well. None of this is really relevant except to explain that cross-env is installed globally on my deployment, in case that's relevant.
My package.json:
{
"private": true,
"scripts": {
...
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"axios": "^0.16.2",
"bootstrap-sass": "^3.3.7",
"jquery": "^3.1.1",
"laravel-mix": "^1.0",
"lodash": "^4.17.4",
"vue": "^2.1.10"
}
}
My deployment to AWS fails on npm run production with the following error:
[stderr]/usr/lib/node_modules/cross-env/dist/index.js:42
[stderr] });
[stderr] ^
[stderr]SyntaxError: Unexpected token }
What could be causing this issue? And how can I resolve it? I highly doubt that there's actually a syntax error in cross-env.
I had the same problem and i could fix it by updating node and re-installing npm.
Steps that worked for me:
Update Node using a package manager:
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
Then fresh install:
rm -rf node_modules && npm cache clean --force && npm install
Hope it helps
In my case I had to upgrade both nodejs and npm:
wget https://nodejs.org/dist/v6.9.2/node-v6.9.2-linux-x64.tar.xz
tar -C /usr/local --strip-components 1 -xJf node-v6.9.2-linux-x64.tar.xz
Then I run npm install without any errors.

Angular2 QuickStart npm start is not working correctly

I know Angular2 beta has just been released but I can't reproduce the steps from their official site tutorial ( https://angular.io/guide/quickstart ). Maybe someone has had similar issues and knows what to do in order to fix the this? When I try to start the application with npm start command I get output like this:
0 info it worked if it ends with ok
1 verbose cli [ 'node', '/usr/local/bin/npm', 'start' ]
2 info using npm#2.7.4
3 info using node#v0.12.2
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info prestart angular2-quickstart#1.0.0
6 info start angular2-quickstart#1.0.0
7 verbose unsafe-perm in lifecycle true
8 info angular2-quickstart#1.0.0 Failed to exec start script
9 verbose stack Error: angular2-quickstart#1.0.0 start: `concurrent "npm run tsc:w" "npm run lite" `
9 verbose stack Exit status 127
9 verbose stack at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/lifecycle.js:213:16)
9 verbose stack at EventEmitter.emit (events.js:110:17)
9 verbose stack at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/spawn.js:14:12)
9 verbose stack at ChildProcess.emit (events.js:110:17)
9 verbose stack at maybeClose (child_process.js:1015:16)
9 verbose stack at Process.ChildProcess._handle.onexit (child_process.js:1087:5)
10 verbose pkgid angular2-quickstart#1.0.0
11 verbose cwd /Users/tmrovsky/Documents/angular2/angular2-quickstart
12 error Darwin 13.4.0
13 error argv "node" "/usr/local/bin/npm" "start"
14 error node v0.12.2
15 error npm v2.7.4
16 error code ELIFECYCLE
17 error angular2-quickstart#1.0.0 start: `concurrent "npm run tsc:w" "npm run lite" `
17 error Exit status 127
18 error Failed at the angular2-quickstart#1.0.0 start script 'concurrent "npm run tsc:w" "npm run lite" '.
18 error This is most likely a problem with the angular2-quickstart package,
18 error not with npm itself.
18 error Tell the author that this fails on your system:
18 error concurrent "npm run tsc:w" "npm run lite"
18 error You can get their info via:
18 error npm owner ls angular2-quickstart
18 error There is likely additional logging output above.
19 verbose exit [ 1, true ]
I had:
typescript 1.7.5 version
node 0.12.2 version
Maybe someone could help solve the problem :) ?
package.json:
{
"name": "angular2-quickstart",
"version": "1.0.0",
"scripts": {
"tsc": "tsc",
"tsc:w": "tsc -w",
"lite": "lite-server",
"start": "concurrent \"npm run tsc:w\" \"npm run lite\" "
},
"license": "ISC",
"dependencies": {
"angular2": "2.0.0-beta.0",
"systemjs": "0.19.6",
"es6-promise": "^3.0.2",
"es6-shim": "^0.33.3",
"reflect-metadata": "0.1.2",
"rxjs": "5.0.0-beta.0",
"zone.js": "0.5.10"
},
"devDependencies": {
"concurrently": "^1.0.0",
"lite-server": "^1.3.1",
"typescript": "^1.7.3"
}
}
index.html:
<html>
<head>
<title>Angular 2 QuickStart</title>
<!-- 1. Load libraries -->
<script src="node_modules/es6-shim/es6-shim.js"></script>
<script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="node_modules/rxjs/bundles/Rx.js"></script>
<script src="node_modules/angular2/bundles/angular2.dev.js"></script>
<!-- 2. Configure SystemJS -->
<script>
System.config({
packages: {
app: {
format: 'register',
defaultExtension: 'js'
}
}
});
System.import('app/boot')
.then(null, console.error.bind(console));
</script>
</head>
<!-- 3. Display the application -->
<body>
<my-app>Loading...</my-app>
</body>
</html>
app.components.ts:
import {Component} from 'angular2/core';
#Component({
selector: 'my-app',
template: '<h1>My First Angular 2 App</h1>',
})
export class AppComponent {}
boot.js:
import {bootstrap} from 'angular2/platform/browser'
import {AppComponent} from './app.component'
bootstrap(AppComponent);
Change the start field in package.json from
"start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" "
to
"start": "concurrently \"npm run tsc:w\" \"npm run lite\" "
In order to get npm start running for me, I had to make sure I had globally installed some of the devDependencies. Have you tried:
npm install -g concurrently
npm install -g lite-server
npm install -g typescript
First you need update npm, lite-server and typescript:
sudo npm update -g && sudo npm install -g concurrently lite-server typescript
Delete node_modules folder from your Angular project directory (if exist). Next run:
npm install
After that resolve ENOSPC errors:
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
Finally:
npm start
This is my package.json file:
{
"name": "reservationsystem",
"version": "0.0.1",
"scripts": {
"tsc": "tsc",
"tsc:w": "tsc -w",
"lite": "lite-server",
"start": "concurrent \"npm run tsc:w\" \"npm run lite\" "
},
"dependencies": {
"a2-in-memory-web-api": "~0.1.0",
"angular2": "2.0.0-beta.3",
"es6-promise": "^3.0.2",
"es6-shim": "^0.33.3",
"reflect-metadata": "0.1.2",
"rxjs": "5.0.0-beta.0",
"systemjs": "0.19.17",
"zone.js": "0.5.11"
},
"devDependencies": {
"concurrently": "^1.0.0",
"lite-server": "^2.0.1",
"typescript": "^1.7.5"
}
}
I had the same error on windows 10. It looks like it's problem with concurrently npm package. I found 2 options how to solve this error:
1. Run both commands in 2 separate cmds:
in the first one run: npm run tsc:w
in the second one: npm run lite
2. Change package.json
just change the start option to this:
"start": "tsc && npm run tsc:w | npm run lite",
Here's how I solved the problem today after hours of trying all of these different solutions - (for anyone looking for another way still).
Open 2 instances of cmd at your quickstart dir:
window #1:
npm run build:watch
then...
window #2:
npm run serve
It will then open in the browser and work as expected
I had a similar problem after copying the angular2-quickstart folder (including node_modules) to create the angular2-tour-of-heroes folder. This was wierd because the original was compiling fine but the copy was not...
npm run tsc
I was able to resolve the issue by deleting the node_modules folder and re-running npm install.
This was a surprise to me, so I did a diff between the 2 folders...
diff -rw angular2-quickstart/node_modules/ angular2-tour-of-heroes/node_modules/
there were a LOT of differences, a lot of 'where' diffs in the package.json files like this:-
diff -rw angular2-quickstart/node_modules/yargs/package.json angular2-tour-of-heroes/node_modules/yargs/package.json
5c5
< "/Users/michael/Tutorials/angular2/angular2-quickstart/node_modules/lite-server"
---
> "/Users/michael/Tutorials/angular2/angular2-tour-of-heroes/node_modules/lite-server"
...which kind of makes sense but there were also some like this:-
diff -rw angular2-quickstart/node_modules/utf-8-validate/build/gyp-mac-tool angular2-tour-of-heroes/node_modules/utf-8-validate/build/gyp-mac-tool
607c607,608
< return {k: self._ExpandVariables(data[k], substitutions) for k in data}
---
> return dict((k, self._ExpandVariables(data[k],
> substitutions)) for k in data)
...which I don't understand at all.
Oh well, Hope this helps.
Change the start field in package.json from:
"start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" "
To:
"start": "concurrently \"npm run tsc:w\" \"npm run lite\" "
It really helped.
This answer is in relation to the excellent Pluralsight course "Angular 2 Fundamentals" by Jim Cooper.
If like me you are having trouble getting started running the command npm start on a Windows 10 machine then I suggest the following:
Start git bash as administrator (follow the steps in the video)
Navigate to the project directory (ng2-fundamentals) and then type the following commands:
npm config get registry
npm cache clean
npm install
Once the installation is complete you will need to modify the get-shell.js file located in the spawn-default-shell module inside the node_modules folder as follows:
Change the following:
const DETECT_SH_REGEX = /sh$/;
to this:
const DETECT_SH_REGEX = /sh/;
Note the $ removed from the end of the sh string (credit to the original author of this fix alfian777 who posted the solution on github)
Save the file and then go to your git bash console and type npm start
You shouldn't see any errors now and the localhost page will start up in your default browser (alternatively open your browser and navigate to http://localhost:8808/).
None of these answers helped with Ubuntu. Finally I ran across a solution from John Papa (lite-server's author).
On Ubuntu 15.10 the Angular 2 Quick Start sprang to life after running this at the terminal:
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf
&& sudo sysctl -p
Apparently it increases the number of available File Watches.
Answer Source: https://github.com/johnpapa/lite-server/issues/9
I encountered this same issue. However, none of the above answers were proper solutions for me. It turns out it was due more to my dev environment then any of the versions of things.
Since I used Visual Studio Code, I set up a build task in VSC to compile TypeScript as a watcher. This was the issue. VSC had already started a NPM task for TSC and so when executing the tutorial's 'start' script, it was having issues with the fact that VSC was still running tsc -w.
I stopped the task in VSC and reran the 'start' script and it worked just fine.
Solution A: Stop and npm Start
VSC Command>Tasks: Terminate running tasks
Terminal $ npm start
After that to bring everything working together I change the start script to just start the server and not actually launch TSC.
Solution B: Change npm start script
Replace
"start": "concurrent \"npm run tsc:w\" \"npm run lite\" "
with
"start": "npm run lite"
Solution C: Just run the lite server command
`npm run lite`
I solved my issue with the Quick Start program by following below link.
Angular 2 QuickStart Live-server error
Change the Package.json Scripts Settings
"start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\",
to:
"start": "concurrently \"npm run tsc:w\" \"npm run lite\" ",
This answer is for Windows 10 users only and as you'll see below, I suspect the problem is happening only for those users:
To find out what is happening, you can run the command on PowerShell and it will tell you what is the actual problem:
PS C:\Users\Laurent-Philippe> tsc && concurrently "tsc -w" "lite-server"
At line:1 char:5
+ tsc && concurrently "tsc -w" "lite-server"
+ ~~
The token '&&' is not a valid statement separator in this version.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : InvalidEndOfLine
Basically, the message explains that the token "&&" is not yet valid with Windows 10. And for those wondering, the same command replacing && with &, informed us that the ampersand operator is reserved for future use:
(&) character is not allowed. The & operator is reserved for future use; wrap an ampersand in double quotation marks ("&") to pass it as part of a string.
Conclusions:
if you want to manually launch this command from the powershell, you can use this instead:
tsc "&" concurrently "tsc -w" "lite-server"
if you want to launch your application with npm start, replace the start line in your package.json by:
"start": "tsc & concurrently \"tsc -w\" \"lite-server\" "
alternatively, the answer of user60108 also works because he is not using the ampersand:
"start": "concurrently \"npm run tsc:w\" \"npm run lite\" "
It's most likely that your NPM version is old, i recently had this on a developer machine at work, type:
npm -v
If it's anything less than the current stable version, and you can just update your Node.js install from here https://nodejs.org/en/ :)
This worked me, put /// <reference path="../node_modules/angular2/typings/browser.d.ts" /> at the top of bootstraping file.
For example:-
In boot.ts
/// <reference path="../node_modules/angular2/typings/browser.d.ts" />
import {bootstrap} from 'angular2/platform/browser'
import {AppComponent} from './app.component'
bootstrap(AppComponent);
Note:- Make sure you have mention the correct reference path.
In devDependencies typescript is 1.7.3 but you have 1.7.5 fix common one.
Import your js files in the correct order in index.html.
for more info refer this repository https://github.com/pkozlowski-opensource/ng2-play/blob/master/index.html
or refer to my repository here
https://github.com/MrPardeep/Angular2-DatePicker
index.html
<script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="node_modules/es6-shim/es6-shim.min.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script>
System.config({
defaultJSExtensions: true,
map: {
rxjs: 'node_modules/rxjs'
},
packages: {
rxjs: {
defaultExtension: 'js'
}
}
});
</script>
<script src="node_modules/angular2/bundles/angular2.dev.js"></script>
<script src="node_modules/rxjs/bundles/Rx.js"></script>
<script src="node_modules/angular2/bundles/router.dev.js"></script>
<script src="node_modules/angular2/bundles/http.dev.js"></script>
<script>
System.import('dist/bootstrap');
</script>
Try this:
Install Latest versions npm/nodejs I purged my npm installation
After that, install tsd npm install -g tsd
Then clone https://github.com/johnpapa/angular2-tour-of-heroes.git
Finally npm i and npm start
Installing the packages globally is one way to do it, but this restricts you to using the same version across all projects in which they are used.
Instead, you can prefix your npm scripts with ./node_modules/.bin. In your case, the package.json would look like this:
{
"name": "reservationsystem",
"version": "0.0.1",
"scripts": {
"tsc": "./node_modules/.bin/tsc",
"tsc:w": "npm run tsc -w",
"lite": "./node_modules/.bin/lite-server",
"start": "./node_modules/.bin/concurrent \"npm run tsc:w\" \"npm run lite\" "
},
"dependencies": {
"a2-in-memory-web-api": "~0.1.0",
"angular2": "2.0.0-beta.3",
"es6-promise": "^3.0.2",
"es6-shim": "^0.33.3",
"reflect-metadata": "0.1.2",
"rxjs": "5.0.0-beta.0",
"systemjs": "0.19.17",
"zone.js": "0.5.11"
},
"devDependencies": {
"concurrently": "^1.0.0",
"lite-server": "^2.0.1",
"typescript": "^1.7.5"
}
}
I think npm is supposed to supply the ./node_modules/.bin in front of each "script" command that's in that directory by default, which is why the original package.json looked the way it did. I am not sure if that feature is in every release of npm, or if there's some config setting you're supposed to specify. It'd be worth looking into!
I had the same problem, we both forgot to include the 's' on components here:
import {AppComponent} from './app.component'
Should be:
boot.js:
import {bootstrap} from 'angular2/platform/browser'
import {AppComponent} from './app.components'
bootstrap(AppComponent);
I had the same error on OS X (node v6.2.0 and npm v3.9.3 installed with homebrew) and it was not solved by any of the above. I had to add full paths to the commands being run by concurrently.
In package.json, I changed this:
"start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" ",
to this:
"start": "tsc && concurrently \"/Users/kyen/.node/bin/npm run tsc:w\" \"/Users/kyen/.node/bin/npm run lite\" ",
You will, of course, need to update the correct paths based on where your node global binaries are stored. Note that I didn't need to add the path to the first tsc command. It seems only concurrently needs the full paths specified.
I met the same error. And after a lot search, I finally found this one: Angular2 application install & run via package.json.
Then I tried to replace
"scripts": {
"start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" ",
"lite": "lite-server",
"postinstall": "typings install",
"tsc": "tsc",
"tsc:w": "tsc -w",
"typings": "typings"
},
to
"scripts": {
"start": "concurrently \"npm run tsc:w\" \"npm run lite\" ",
"lite": "lite-server",
"postinstall": "typings install",
"tsc": "tsc",
"tsc:w": "tsc -w",
"typings": "typings"
},
Hope it helps who get the same error.
PS: My error is not the same as Tomasz, which is my npm version is 3.7.3 and node version is 5.9.1.
Uninstall all existing node packages.
Update node and npm.As it is given in documentation as at least node v5.x.x and npm 3.x.x else it will cause errors .
Do npm clean.
Then do npm install, npm start.
This solved the issue for me.
For Ubuntu 16.x users, installing latest version 5.x solves my issue in ubuntu
curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash -
sudo apt-get install -y nodejs
Seemingly there is more than one way in which angular2-quickstart can fail to start. I had the same issue running Angular2 version 2.0.0 under a fresh install of node 6.6.0 / npm 3.10.3 on Windows 7. In my case running npm start dumped a ton of typescript errors:
c:\git\angular2-quickstart>npm start
> angular2-quickstart#1.0.0 start c:\git\angular2-quickstart
> tsc && concurrently "npm run tsc:w" "npm run lite"
node_modules/#angular/common/src/directives/ng_class.d.ts(46,34): error TS2304: Cannot find name 'Set'.
node_modules/#angular/common/src/pipes/async_pipe.d.ts(39,38): error TS2304: Cannot find name 'Promise'.
(...)
This issue is discussed in angular quickstart issue #63, "typings" not being installed correctly. That ticket gives the fix as
$ ./node_modules/.bin/typings install
which worked for me. (I'm not sure of the "right" way to do this yet.)
Please make sure the names are correct, thus changing component in boot.js to components.
Go to https://github.com/npm/npm/issues/14075 address. And try juaniliska's answer. Maybe help you.
npm config get registry
npm cache clean
npm install
In the package.json file, I removed the line which had "prestart": "npm run build". This appears to be a blocking command, and occurs before (npm) start, thus preventing the other start commands.
Change start in angular.json to either "start": "ng serve --host 0.0.0.0" or "start": "lite-server" and run.Also check if you've installed angular/cli properly or not.
I the quick start tutorial I went through the steps up until npm start. Then i got this error. Then I deleted the node_modules folder under angular-quickstart and ran npm install again. Now it works.
If you use proxy it may cause this error:
npm config set proxy http://username:pass#proxy:port
npm config set https-proxy http://username:pass#proxy:port
create a file named .typingsrc in your application folder that includes:
proxy = (value on step 1)
https-proxy = (value on step 1)
run npm cache clean
run npm install
run npm typings install
run npm start
it will work then
Add the following section in tsconfig.json:
"compilerOptions": {
"target": "es5",
"module": "system",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
}
and in \node_modules\typings\typings.json:
"ambientDependencies": {
"es6-shim": "github:DefinitelyTyped/DefinitelyTyped/es6-shim /es6-shim.d.ts#6697d6f7dadbf5773cb40ecda35a76027e0783b2"
}
After these changes it works for me.

Resources