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

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

Related

AngularJs with Docker throw Uncaught referenceError : Angular is not defined

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"]

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.

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

How can you get Grunt livereload to work inside Docker?

I'm trying to use Docker as a dev environment in Windows.
The app I'm developing uses Node, NPM and Bower for setting up the dev tools, and Grunt for its task running, and includes a live reload so the app updates when the code changes. Pretty standard. It works fine outside of Docker but I keep running into the Grunt error Fatal error: Unable to find local grunt. no matter how I try to do it inside Docker.
My latest effort involves installing all the npm and bower dependencies to an app directory in the image at build time, as well as copying the app's Gruntfile.js to that directory.
Then in Docker-Compose I create a Volume that is linked to the host app, and ask Grunt to watch that volume using Grunt's --base option. It still won't work. I still get the fatal error.
Here are the Docker files in question:
Dockerfile:
# Pull base image.
FROM node:5.1
# Setup environment
ENV NODE_ENV development
# Setup build folder
RUN mkdir /app
WORKDIR /app
# Build apps
#globals
RUN npm install -g bower
RUN echo '{ "allow_root": true }' > /root/.bowerrc
RUN npm install -g grunt
RUN npm install -g grunt-cli
RUN apt-get update
RUN apt-get install ruby-compass -y
#locals
ADD package.json /app/
ADD Gruntfile.js /app/
RUN npm install
ADD bower.json /app/
RUN bower install
docker-compose.yml:
angular:
build: .
command: sh /host_app/startup.sh
volumes:
- .:/host_app
net: "host"
startup.sh:
#!/bin/bash
grunt --base /host_app serve
The only way I can actually get the app to run at all in Docker is to copy all the files over to the image at build time, create the dev dependencies there and then, and run Grunt against the copied files. But then I have to run a new build every time I change anything in my app.
There must be a way? My Django app is able to do a live reload in Docker no problems, as per Docker's own Django quick startup instructions. So I know live reload can work with Docker.
PS: I have tried leaving the Gruntfile on the Volume and using Grunt's --gruntfile option but it still crashes. I have also tried creating the dependencies at Docker-Compose time, in the shared Volume, but I run into npm errors to do with unpacking tars. I get the impression that the VM can't cope with the amount of data running over the shared file system and chokes, or maybe that the Windows file system can't store the Linux files properly. Or something.

Resources