npm ERR! missing script: build:universal - node.js

I am trying to run my Angular application on the server side and I am facing these errors:
npm ERR! missing script: build:universal
npm ERR! A complete log of this run can be found in: npm ERR!
/home/training/.npm/_logs/2018-10-03T11_50_40_593Z-debug.log
I used the official Angular application for doing this
https://angular.io/guide/universal
The universal build is causing errors shown below:
0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/nodejs',
1 verbose cli '/usr/local/bin/npm',
1 verbose cli 'run',
1 verbose cli 'build:universal' ]
2 info using npm#6.2.0
3 info using node#v10.8.0
4 verbose stack Error: missing script: build:universal
4 verbose stack at run (/usr/local/lib/node_modules/npm/lib/run-script.js:155:19)
4 verbose stack at /usr/local/lib/node_modules/npm/lib/run-script.js:63:5
4 verbose stack at /usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:115:5
4 verbose stack at /usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:418:5
4 verbose stack at checkBinReferences_ (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:373:45)
4 verbose stack at final (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:416:3)
4 verbose stack at then (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:160:5)
4 verbose stack at /usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:280:12
4 verbose stack at /usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:78:16
4 verbose stack at FSReqWrap.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:53:3)
5 verbose cwd /home/training/Desktop/vishnu/TemplateAppv6
6 verbose Linux 4.4.0-134-generic
7 verbose argv "/usr/bin/nodejs" "/usr/local/bin/npm" "run" "build:universal"
8 verbose node v10.8.0
9 verbose npm v6.2.0
10 error missing script: build:universal
11 verbose exit [ 1, true ]

As implied in my comment, you may have forgotten to add the build-script to your project:
From the universal docs
Build and run with universal: Now that you've created the TypeScript
and Webpack config files and configured the Angular CLI, you can build
and run the Universal application.
First add the build and serve commands to the scripts section of the
package.json:
"scripts": {
...
"build:ssr": "npm run build:client-and-server-bundles && npm run webpack:server",
"serve:ssr": "node dist/server",
"build:client-and-server-bundles": "ng build --prod && ng run angular.io-example:server",
"webpack:server": "webpack --config webpack.server.config.js --progress --colors"
...
}
So check you package.json and try the build again..

Related

Error running npm Script when starting Docker Container

In my DockerFile i have this setup as my command.
CMD config/startserver.sh
Having problem getting npm run build to work. I have no problem running npm run build when i go into the conatiner and run docekr exec npm run build manually but for some reason running it inside the .sh causes a problem. Any ideas as to why running npm run build inside an .sh could be causing a problem.
npm run build
pm2 start server.js -f -- 5000
pm2 start server.js -f -- 5001
pm2 start server.js -f -- 5002
pm2 start server.js -f -- 5003
pm2 start server.js -f -- 5004
nginx -g "daemon off;"
wait
0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'run', 'build\r' ]
2 info using npm#6.13.4
3 info using node#v10.19.0
4 verbose config Skipping project config: /home/lgd/.npmrc. (matches userconfig)
5 verbose stack Error: missing script: build
5 verbose stack
5 verbose stack Did you mean this?
5 verbose stack build
5 verbose stack at run (/usr/lib/node_modules/npm/lib/run-script.js:155:19)
5 verbose stack at /usr/lib/node_modules/npm/lib/run-script.js:63:5
5 verbose stack at /usr/lib/node_modules/npm/node_modules/read-package-json/read-json.js:116:5
5 verbose stack at /usr/lib/node_modules/npm/node_modules/read-package-json/read-json.js:436:5
5 verbose stack at checkBinReferences_ (/usr/lib/node_modules/npm/node_modules/read-package-json/read-json.js:391:45)
5 verbose stack at final (/usr/lib/node_modules/npm/node_modules/read-package-json/read-json.js:434:3)
5 verbose stack at then (/usr/lib/node_modules/npm/node_modules/read-package-json/read-json.js:161:5)
5 verbose stack at ReadFileContext.<anonymous> (/usr/lib/node_modules/npm/node_modules/read-package-json/read-json.js:350:20)
5 verbose stack at ReadFileContext.callback (/usr/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:115:16)
5 verbose stack at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:237:13)
6 verbose cwd /home/lgd
7 verbose Linux 4.19.76-linuxkit
8 verbose argv "/usr/bin/node" "/usr/bin/npm" "run" "build\r"
9 verbose node v10.19.0
10 verbose npm v6.13.4
11 error missing script: build
11 error
11 error Did you mean this?
11 error build
12 verbose exit [ 1, true ]
Had to revert back to calling script in Docker because i was getting permission errors on my Server when i pushed my container.
I think David was right and i just needed to fix my line endings.
I ended up changing
CMD config/startserver.sh
to
CMD [ "npm", "run", "start-production" ]
And added to my package.json scripts
"start-production": "npm run build && config/startserver.sh"

Why can i not run my project in development mode?

When I use npm run serve, I get following message.
PS C:\Users\Jan\Desktop\projektgruppe\Main> npm run serve
> editor#0.1.0 serve C:\Users\Jan\Desktop\projektgruppe\Main
> concurrently "nodemon -L --inspect=0.0.0.0:9001 ./server/index.js" "vue-cli-service build ./src/main.js --mode development --watch"
[0] Error occurred when executing command: nodemon -L --inspect=0.0.0.0:9001 ./server/index.js
[0] Error: spawn cmd.exe ENOENT
[0] at Process.ChildProcess._handle.onexit (internal/child_process.js:264:19)
[0] at onErrorNT (internal/child_process.js:456:16)
[0] at processTicksAndRejections (internal/process/task_queues.js:81:21)
[1] Error occurred when executing command: vue-cli-service build ./src/main.js --mode development --watch
[1] Error: spawn cmd.exe ENOENT
[1] at Process.ChildProcess._handle.onexit (internal/child_process.js:264:19)
[1] at onErrorNT (internal/child_process.js:456:16)
[1] at processTicksAndRejections (internal/process/task_queues.js:81:21)
[1] vue-cli-service build ./src/main.js --mode development --watch exited with code -4058
[0] nodemon -L --inspect=0.0.0.0:9001 ./server/index.js exited with code -4058
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! editor#0.1.0 serve: `concurrently "nodemon -L --inspect=0.0.0.0:9001 ./server/index.js" "vue-cli-service build ./src/main.js --mode development --watch"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the editor#0.1.0 serve script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
and my log file is this
0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli 'C:\\Program Files\\node\\node.exe',
1 verbose cli 'C:\\Program Files\\node\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'run',
1 verbose cli 'serve'
1 verbose cli ]
2 info using npm#6.13.6
3 info using node#v12.14.1
4 verbose run-script [ 'preserve', 'serve', 'postserve' ]
5 info lifecycle editor#0.1.0~preserve: editor#0.1.0
6 info lifecycle editor#0.1.0~serve: editor#0.1.0
7 verbose lifecycle editor#0.1.0~serve: unsafe-perm in lifecycle true
8 verbose lifecycle editor#0.1.0~serve: PATH: C:\Program Files\node\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Users\Jan\Desktop\projektgruppe\Main\node_modules\.bin;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\node\;C:\Program Files\Git\cmd;C:\Users\Jan\AppData\Local\Microsoft\WindowsApps;C:\Users\Jan\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\Jan\AppData\Roaming\npm
9 verbose lifecycle editor#0.1.0~serve: CWD: C:\Users\Jan\Desktop\projektgruppe\Main
10 silly lifecycle editor#0.1.0~serve: Args: [
10 silly lifecycle '/d /s /c',
10 silly lifecycle 'concurrently "nodemon -L --inspect=0.0.0.0:9001 ./server/index.js" "vue-cli-service build ./src/main.js --mode development --watch"'
10 silly lifecycle ]
11 silly lifecycle editor#0.1.0~serve: Returned: code: 1 signal: null
12 info lifecycle editor#0.1.0~serve: Failed to exec serve script
13 verbose stack Error: editor#0.1.0 serve: `concurrently "nodemon -L --inspect=0.0.0.0:9001 ./server/index.js" "vue-cli-service build ./src/main.js --mode development --watch"`
13 verbose stack Exit status 1
13 verbose stack at EventEmitter.<anonymous> (C:\Program Files\node\node_modules\npm\node_modules\npm-lifecycle\index.js:332:16)
13 verbose stack at EventEmitter.emit (events.js:223:5)
13 verbose stack at ChildProcess.<anonymous> (C:\Program Files\node\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:223:5)
13 verbose stack at maybeClose (internal/child_process.js:1021:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
14 verbose pkgid editor#0.1.0
15 verbose cwd C:\Users\Jan\Desktop\projektgruppe\Main
16 verbose Windows_NT 10.0.18363
17 verbose argv "C:\\Program Files\\node\\node.exe" "C:\\Program Files\\node\\node_modules\\npm\\bin\\npm-cli.js" "run" "serve"
18 verbose node v12.14.1
19 verbose npm v6.13.6
20 error code ELIFECYCLE
21 error errno 1
22 error editor#0.1.0 serve: `concurrently "nodemon -L --inspect=0.0.0.0:9001 ./server/index.js" "vue-cli-service build ./src/main.js --mode development --watch"`
22 error Exit status 1
23 error Failed at the editor#0.1.0 serve script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
It always worked, but now not. I tried many times to uninstall node modules. I reinstalled many times node, but I can not find the mistake. I have no Problem, when I just build it and start it. But that is not nice for development.
"start": "node ./server/index.js",
"serve": "concurrently \"nodemon -L --inspect=0.0.0.0:9001 ./server/index.js\" \"vue-cli-service build ./src/main.js --mode development --watch\"",
"build": "vue-cli-service build ./src/main.js",
Would be so glad for any help.
Thanks

Why does this error happen? "npm run dev missing script error"

I've been trying to follow the following tutorial:
https://github.com/digitsensitive/phaser3-typescript/blob/master/README.md
These are the steps that I had to follow
Prerequisites
Download and install npm with Node.js # https://nodejs.org/en
Installing
Select a folder, navigate to it, and clone this repository with this command-line:
git clone https://github.com/digitsensitive/phaser3-typescript.git
Install the dependencies with this command-line:
npm install
If you use yarn just replace npm with yarn
Building and Running
Perform a quick build (bundle.js) and start server:
npm run dev
I've never used node.js and npm before so I'm stumbling across some newbie mistakes. One error I get is that when I try to run npm run dev, Git bash returns the following error code:
npm ERR! missing script: dev
0 info it worked if it ends with ok
1 verbose cli [ 'C:\Program Files\nodejs\node.exe',
1 verbose cli 'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js',
1 verbose cli 'run',
1 verbose cli 'dev' ]
2 info using npm#6.4.1
3 info using node#v10.15.3
4 verbose stack Error: missing script: dev
4 verbose stack at run (C:\Program Files\nodejs\node_modules\npm\lib\run-script.js:155:19)
4 verbose stack at C:\Program Files\nodejs\node_modules\npm\lib\run-script.js:63:5
4 verbose stack at C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:115:5
4 verbose stack at C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:418:5
4 verbose stack at checkBinReferences_ (C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:373:45)
4 verbose stack at final (C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:416:3)
4 verbose stack at then (C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:160:5)
4 verbose stack at ReadFileContext. (C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:332:20)
4 verbose stack at ReadFileContext.callback (C:\Program Files\nodejs\node_modules\npm\node_modules\graceful-fs\graceful-fs.js:78:16)
4 verbose stack at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:237:13)
5 verbose cwd C:\Users\Yassi\TEST
6 verbose Windows_NT 10.0.17134
I don't know what I should be adding to my package.json file to make this work. Could anyone help me with this please?
I made a package.json using init, but the tutorial doesn't state that I have to do this. I don't know why I should manually make a package.json file in the first place.
Your package.json is missing a "dev" key in the scripts section.
Or you are running the npm command from a wrong directory.
Please use a package.json from their project. I think this will work
From here:
https://github.com/digitsensitive/phaser3-typescript?files=1
Just add div in scripts object in your package.json file
as you see
"scripts": {
"start": "node ./bin/www",
"dev": "nodemon ./bin/www"
},
that's if you use nodemon package

Docker build for React App failing in Gitlab CI runner

I have been trying to create a react app Gitlab CI but it keeps failing on the RUN npm run build (tried RUN CI=true npm run build too) when trying to create a docker file.
Here's my Dockerfile
FROM node:8.11.1
# Create app directory
WORKDIR /app/
# Install app dependencies
RUN npm -g install serve
# A wildcard is used to ensure both package.json AND package-lock.json are copied
COPY package*.json /app/
RUN npm install
# Bundle app source
COPY . /app/
RUN ls /app/
#Build react/vue/angular bundle static files
RUN npm run build
EXPOSE 5000
# serve build folder on port 5000
CMD ["serve", "-s", "build", "-p", "5000"]
fails at step RUN npm run build with the following error:
Step 8/10 : RUN npm run build
---> Running in d4b3bc5de229
> payed-fe#0.1.0 build /app
> react-scripts build
Creating an optimized production build...
Failed to compile.
./src/index.js
Cannot find file './app' in './src'.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! payed-fe#0.1.0 build: `react-scripts build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the payed-fe#0.1.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! /root/.npm/_logs/2018-12-20T15_52_14_979Z-debug.log
The command '/bin/sh -c npm run build' returned a non-zero code: 1
ERROR: Job failed: exit code 1
However on my local machine everything works like a charm (npm start, npm run build, even same Dockerfile on my local builds successfully).
Thanks in Advance!
--- EDIT 1 ---
yes ls gives the same output on my local system and CI.
./src/index.js is just my entry file. Here are the contents:
import React from "react";
import ReactDOM from "react-dom";
import App from "./app";
import * as serviceWorker from "./serviceWorker";
ReactDOM.render(<App />, document.getElementById("root"));
serviceWorker.unregister();
And yes the paths are perfectly alright as it is running successfully on my local machine.
--- EDIT 2 ---
Output of /root/.npm/_logs/*.log after I changed the working dir to /payed - Still no luck!
0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'build' ]
2 info using npm#5.6.0
3 info using node#v8.11.1
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle payed-fe#0.1.0~prebuild: payed-fe#0.1.0
6 info lifecycle payed-fe#0.1.0~build: payed-fe#0.1.0
7 verbose lifecycle payed-fe#0.1.0~build: unsafe-perm in lifecycle true
8 verbose lifecycle payed-fe#0.1.0~build: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/payed/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
9 verbose lifecycle payed-fe#0.1.0~build: CWD: /payed
10 silly lifecycle payed-fe#0.1.0~build: Args: [ '-c', 'react-scripts build' ]
11 silly lifecycle payed-fe#0.1.0~build: Returned: code: 1 signal: null
12 info lifecycle payed-fe#0.1.0~build: Failed to exec build script
13 verbose stack Error: payed-fe#0.1.0 build: `react-scripts build`
13 verbose stack Exit status 1
13 verbose stack at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:285:16)
13 verbose stack at emitTwo (events.js:126:13)
13 verbose stack at EventEmitter.emit (events.js:214:7)
13 verbose stack at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack at emitTwo (events.js:126:13)
13 verbose stack at ChildProcess.emit (events.js:214:7)
13 verbose stack at maybeClose (internal/child_process.js:925:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
14 verbose pkgid payed-fe#0.1.0
15 verbose cwd /payed
16 verbose Linux 4.14.48-coreos-r2
17 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "build"
18 verbose node v8.11.1
19 verbose npm v5.6.0
20 error code ELIFECYCLE
21 error errno 1
22 error payed-fe#0.1.0 build: `react-scripts build`
22 error Exit status 1
23 error Failed at the payed-fe#0.1.0 build script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
Try CI=false
CI=true is the default...

brunch build --production fails only in production

Out of the blue build script started to fail. No changes in environment or configs at all. Works fine in dev, fails in prod.
Both dev and prod (both Ubuntus):
$ npm -v
5.3.0
$ node -v
v6.11.2
In dev:
oleg#DevVM ~/Code/loaded.bike/assets $ npm run deploy
> # deploy /home/oleg/Code/loaded.bike/assets
> brunch build --production
17:49:59 - info: compiling
17:49:59 - info: compiled 19 files into 2 files, copied 32 in 6.9 sec
In prod:
deploy#loaded-bike-app:~/builds/assets$ npm run deploy
> # deploy /home/deploy/builds/assets
> brunch build --production
00:45:30 - error: Initialization error - Could not load global module 'jquery'. Possible solution: add 'jquery' to package.json and `npm install`. Could not load global module 'jquery'. Possible solution: add 'jquery' to package.json and `npm install`.
Stack trace was suppressed. Run with `LOGGY_STACKS=1` to see the trace.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! # deploy: `brunch build --production`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the # deploy 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! /home/deploy/.npm/_logs/2017-08-12T00_45_30_084Z-debug.log
Full log:
0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'deploy' ]
2 info using npm#5.3.0
3 info using node#v6.11.2
4 verbose run-script [ 'predeploy', 'deploy', 'postdeploy' ]
5 info lifecycle #~predeploy: #
6 info lifecycle #~deploy: #
7 verbose lifecycle #~deploy: unsafe-perm in lifecycle true
8 verbose lifecycle #~deploy: PATH: /usr/local/lib/node_modules/npm/bin/node-gyp-bin:/home/deploy/builds/assets/node_modules/.bin:/home/deploy/bin:/home/deploy/.local
/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
9 verbose lifecycle #~deploy: CWD: /home/deploy/builds/assets
10 silly lifecycle #~deploy: Args: [ '-c', 'brunch build --production' ]
11 silly lifecycle #~deploy: Returned: code: 1 signal: null
12 info lifecycle #~deploy: Failed to exec deploy script
13 verbose stack Error: # deploy: `brunch build --production`
13 verbose stack Exit status 1
13 verbose stack at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/lifecycle.js:289:16)
13 verbose stack at emitTwo (events.js:106:13)
13 verbose stack at EventEmitter.emit (events.js:191:7)
13 verbose stack at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/spawn.js:40:14)
13 verbose stack at emitTwo (events.js:106:13)
13 verbose stack at ChildProcess.emit (events.js:191:7)
13 verbose stack at maybeClose (internal/child_process.js:891:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
14 verbose pkgid #
15 verbose cwd /home/deploy/builds/assets
16 verbose Linux 4.8.0-41-generic
17 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "deploy"
18 verbose node v6.11.2
19 verbose npm v5.3.0
20 error code ELIFECYCLE
21 error errno 1
22 error # deploy: `brunch build --production`
22 error Exit status 1
23 error Failed at the # deploy script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
Adding jquery, tether to package.json fixes require error but then it just chokes on sass compile. Is this just JS missfiring async function out of order or what is going here? Once again, it started to fail completely out of the blue. Deployed just fine yesterday and today if fails without me changing anything. Any clue what might be wrong here?
EDIT:
package.json:
{
"repository": {},
"license": "MIT",
"scripts": {
"deploy": "brunch build --production",
"watch": "brunch watch --stdin"
},
"dependencies": {
"bootstrap": "^4.0.0-alpha.6",
"phoenix": "file:../deps/phoenix",
"phoenix_html": "file:../deps/phoenix_html"
},
"devDependencies": {
"babel-brunch": "6.0.6",
"brunch": "2.10.10",
"clean-css-brunch": "2.10.0",
"css-brunch": "2.10.0",
"sass-brunch": "2.10.4",
"uglify-js-brunch": "2.1.1"
}
}
I'm actually seeing this crap on prod (but not on dev)
npm ERR! peer dep missing: jquery#>=3.0.0, required by bootstrap#4.0.0-beta
npm ERR! peer dep missing: popper.js#^1.11.0, required by bootstrap#4.0.0-beta
What is that about? Bootstrap defines those as dependencies (not peerDependency) in its own package.json. npm doesn't pull in dependencies now?
"bootstrap": "^4.0.0-alpha.6"
Needed to lock the version. Bootstrap went from alpha.6 to beta yesterday. Messed everything up. No idea why is started to fail only on one machine (even after npm cache clear). Sass compile fails under beta, so I locked it to alpha.6 for now.
I think I need to start locking dependency versions. This took way too long to figure out.

Resources