AngularJs with Docker throw Uncaught referenceError : Angular is not defined - node.js

I'm trying to containerized my app using docker and it throw Uncaught referenceError : Angular is not defined when I build using npm start
Here is my docker file:
FROM node:6.9.5-onbuild
COPY . .
RUN npm install -g bower
RUN npm install -g gulp-cli
RUN npm install
CMD ["gulp"]
Before it was throwing that it doesn't found bower-components folder, so i solved it using bower install to fix it, couldn't solve in docker.
When i execute my app with npm start without docker, it works just fine.
I'm using node 6.9.5 in my app.

Solved changing the node image from docker.
alpine image is more clean, I guess...
FROM node:6.9.5-alpine
COPY . .
RUN npm install
CMD ["npm", "start"]

Related

ReferenceError: window is not defined "at AuthService.8klp.AuthService.init"

Outside the Docker Application is working fine when I am trying to build using Dockerfile and run the container I am getting the above issue.
ReferenceError: window is not defined
at AuthService.8klp.AuthService.init (/usr/local/iquanta-ang/dist/server/main.js:93765:9)
at new AuthService (/usr/local/iquanta-ang/dist/server/main.js:93760:14)
at AuthService_Factory (/usr/local/iquanta-ang/dist/server/main.js:93800:108)
at _callFactory (/usr/local/iquanta-ang/dist/server/main.js:75898:24)
at _createProviderInstance (/usr/local/iquanta-ang/dist/server/main.js:75856:30)
at resolveNgModuleDep (/usr/local/iquanta-ang/dist/server/main.js:75831:21)
at NgModuleRef_.get (/usr/local/iquanta-ang/dist/server/main.js:76507:20)
at resolveDep (/usr/local/iquanta-ang/dist/server/main.js:76878:49)
at createClass (/usr/local/iquanta-ang/dist/server/main.js:76758:36)
at createDirectiveInstance (/usr/local/iquanta-ang/dist/server/main.js:76629:24)
This issue was because recently we have implemented Google Gmail Login POP Up on our website.
After implementing the Gmail Login POP UP on our website issue has started on Docker Container.
Is there any dependencies need to be installed for "window is not defined"
Can someone please help me to fix this issue.
Here is my Dockerfile.
`FROM node:16 as dev-build
ENV NPM_CONFIG_PREFIX=/home/node/.npm-global
ENV PATH=$PATH:/home/node/.npm-global/bin
WORKDIR /usr/local/angular/
COPY . /usr/local/angular
RUN npm install -g #angular/cli
RUN npm install pm2 -g
RUN npm install
RUN npm run build:ssr
RUN npm run-script build
CMD ["pm2-runtime","/usr/local/angular/dist/server.js"]
EXPOSE 4000`
Regards
Sainath

Add Carbone to Docker image

I have installed Carbone on my local Linux machine using the following command and it is working properly.
npm install carbone
Now, I need to add carbone in my docker image, but I don't know how to add it to the image. Should I add the npm install command to DockerFile or add it to package.json?
I got the following error if I don't add carbone to docker image:
Code : const carbone = require('carbone');
Error: Cannot find module 'carbone'
Carbone have to be used on node projects. You can install through NPM:
npm install carbone --save
Then, you must follow the documentation of the basics:
https://github.com/Ideolys/carbone/#getting-started
If you want to dockerize your application, you can start your container from the image ideolys/carbone-env-docker. It's a ready to go node:8 image with Libreoffice installed. Example of Dockerfile:
FROM ideolys/carbone-env-docker
ENV DIR /app
WORKDIR ${DIR}
COPY . ${DIR}
RUN npm install
# index.js should call carbone functions to generate your report.
CMD [ "node", "index.js" ]
Finally you can build and run the container !
If you need more help or encounter an issue, post an issue on the Carbone Github.

docker npm install serve fails

I'm not very familiar to docker, but I'm trying to put the frontend (written with create-react-app) into the docker container.
I've found a tutorial and followed it, so my Dockerfile looks like this:
FROM node:7.8.0
ENV NPM_CONFIG_LOGLEVEL warn
RUN npm install -g serve
CMD serve -s --port 8081 build
EXPOSE 8081
COPY package.json package.json
COPY npm-shrinkwrap.json npm-shrinkwrap.json
RUN npm install
COPY . .
RUN npm run build --production
In my machine it works ok, but when I try to put it on server (raspberry pi) with docker-compose it fails.
Step 3 : RUN npm install -g serve
ERROR: Service 'frontend' failed to build: rpc error: code = 2 desc = "oci runtime error: exec format error"
I've googled, but haven't found exactly this problem. I even tried to put sudo before npm install, but got an error
/bin/sh: 1: sudo: not found
You can either create your private repository locally or can push it to docker-hub and then try loading it on raspberry-pi.

How to deploy Angular universal

I looking into Angular universal and trying to get my head around deployment.
Github https://github.com/angular/universal-starter
It has Angular 2 Universal + TypeScript 2 + Webpack 2
When I run the command
npm run build
I get the following structure
**Client**
0.bundle
0.bundle.js.map
main.bundle
main.bundle.js.map
**Server**
0.index
0.index.js.map
index
index.js.map
How do I deploy this to a server?
Install dependencies
Run npm install in your terminal at the root of universal-starter
Run the NodeJS backend
Run npm run build:ssr && npm run serve:ssr after npm install has finished, this will host a local nodejs server here: http://localhost:4000 (you can put that in your browser)
Before either of these steps ensure you have NodeJS and NPM installed (NPM comes with the newer builds of NodeJS)

Docker Compose w/ Gulp - Local gulp not found

I am attempting to use gulp inside a Docker container.
I have the following Dockerfile
FROM golang:alpine
RUN apk --update add --no-cache git nodejs
RUN npm install --global gulp
ENV GOPATH=/go PATH=$PATH:/go/bin
VOLUME ["/go/src/github.com/me/sandbox", "/go/pkg","/go/bin"]
WORKDIR /go/src/github.com/me/sandbox
CMD ["gulp"]
and I have the following docker-compose.yml
version: '2'
services:
service:
build: ./service
volumes:
- ./service/src/:/go/src/github.com/me/sandbox
docker-compose build builds successfully, but when I run docker-compose up, I get the following error message
Recreating sandbox_service_1
Attaching to sandbox_service_1
service_1 | [22:03:40] Local gulp not found in /go/src/github.com/me/sandbox
service_1 | [22:03:40] Try running: npm install gulp
I have tried several different things to try to fix it.
Tried also installing gulp-cli globally and locally
Tried installing gulp locally with npm install gulp
Tried moving the npm install --global gulp after the WORKDIR
Tried different paths for volumes.
My guess is that it has something to do with the volumes, because when I get rid of anything having to do with a volume, it doesn't complain.
Mr project structure is shown in screenshot below:
This is what worked for me.
RUN npm install -g gulp
RUN npm link gulp
You need a local version of gulp as well as a global one.
Adding this line should fix your issue
RUN npm i gulp

Resources