I am trying to build a typescript project using docker, but there's an error with tsc.
This is my dockerfile
FROM node:alpine AS build
# Create app directory
RUN mkdir -p /app
WORKDIR /app
COPY package.json .
RUN npm install
COPY . .
RUN npm run build:tsc
# RUN npx tsc -p ./tsconfig.json
# Second stage: run things.
FROM node:12
WORKDIR /app
# Install the Javascript dependencies, only runtime libraries.
COPY package.json .
COPY --from=build /app/dist dist
CMD ["npm","run", "start:dev"]
package.json
"start": "node ./dist/server",
"start:dev": "nodemon ./dist/server | bunyan",
"watch:tsc": "tsc --watch -p ./tsconfig.json",
"build:tsc": "tsc -p ./tsconfig.json",
"heroku-postbuild": "npm run build:tsc",
The error I get
Related
My dockerfile fails to build with the following error:
node: --openssl-legacy-provider is not allowed in NODE_OPTIONS
This is my dockerfile:
FROM node:14-alpine as build
RUN apk update
RUN apk --no-cache --virtual build-dependencies add \
python3 \
g++
WORKDIR /app
# Add the source code to app
COPY ./js /app
# Install all the dependencies
RUN yarn install --frozen-lockfile
RUN yarn bootstrap
# Generate the build of the application
RUN NODE_OPTIONS=--openssl-legacy-provider yarn build
FROM node:14-alpine AS runner
WORKDIR /app
ENV NODE_ENV production
RUN addgroup -g 1001 -S nodejs
RUN adduser -S nextjs -u 1001
Running yarn build works with the following package.json but just not in the docker build:
"scripts" {
"build": "NODE_OPTIONS=--openssl-legacy-provider lerna run build",
}
I am trying to deploy my node application on docker container.
here is my docker file
FROM node:latest
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json /usr/src/app/
ENV NODE_ENV=development
RUN npm install
COPY . /usr/src/app
EXPOSE 3000
CMD [ "npm", "start" ]
here is the module not found error
here is my project directory
here is my code location in linux
It looks like you copy your application source after doing the NPM install.
FROM node:latest
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json /usr/src/app/
COPY . /usr/src/app
ENV NODE_ENV=development
RUN npm install
EXPOSE 3000
CMD [ "npm", "start" ]
I am trying to make a docker file for TypeScript node.js app.
this is my Dockerfile :
FROM node:10 as base
ENV NODE_ENV=production
WORKDIR /app
RUN npm install -g nodemon
COPY package*.json ./
RUN npm install
ENV PATH /app/node_modules/.bin:$PATH
FROM base as dev
ENV NODE_ENV=development
RUN npm install
CMD ["/app/node_modules/.bin/nodemon"]
FROM dev as build
COPY . .
RUN tsc
FROM base as prod
COPY --from=build /app/dist/ .
CMD ["node", "app.js"]
and this is my docker-compose.yml file:
version: '2.4'
services:
ts:
build:
context: .
target: dev
ports:
- "3000:3000"
- "9229:9229"
volumes:
- .:/app
env_file:
- .env
when I run docker-compose up --build:
it gives me this error:
ts_1 | internal/modules/cjs/loader.js:638
ts_1 | throw err;
ts_1 | ^
ts_1 |
ts_1 | Error: Cannot find module 'pstree.remy'
and this is part of the package.json
"scripts": {
"build": "rm -rf dist && tsc --skipLibCheck && cp -r src/public dist",
"start": "node ./dist/app.js",
"start:dev": "npm run build && pm2 start dist/ecosystem.config.js --env development",
"start:prod": "npm run build && pm2 start dist/ecosystem.config.js --env production",
},
I have a node.js application which I am trying to run in docker. Here is the package.json file snippet.
"main": "lib/server.js",
"scripts": {
"clean": "cross-env rm -rf dist",
"build": "cross-env babel lib -d dist",
"start": "npm run clean && npm run build && npm run serve",
"serve": "node dist/index.js",
"dev": "cross-env NODE_ENV=development nodemon lib/server.js --exec babel-node",
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "eslint --ext .js lib/ scripts/ --ignore-pattern node_modules/"
}
And here is the Dockerfile to build the image
#---- Base Node------
FROM node:10.15.1-alpine
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package*.json ./
COPY lib ./lib
RUN npm install --only=production && npm run build
EXPOSE 4201
CMD ["npm", "run", "serve"]
I get the following error when I try to run the image. Here is the screenshot of the error.
The node and npm version are the same on my machine and the base image that I am using to build my image.
When I run the same command locally in my machine it works
Here is the exact command that I am running on my machine and it works.
npm install --only=production
npm run build
npm run serve
Am I doing something wrong here ? Any help is appreciated.
You are using ES6 imports
import x from package
In order to do that, you should have Babel package installed, otherwise it won't know how to import that file
I have Dockerfile:
FROM cloudron/base:0.10.0
ENV PATH /usr/local/node-6.9.5/bin:$PATH
WORKDIR /tmp
COPY package.json /tmp/
RUN npm config set registry http://registry.npmjs.org/ && npm install
WORKDIR /usr/src/app
COPY . /usr/src/app
RUN cp -a /tmp/node_modules /usr/src/app
RUN npm run build
EXPOSE 8000
CMD [ "npm", "run", "start:production" ]
if I run this by:
docker run -p 8000:8000 -t somename/appname
then
going to http://localhost:8000 works fine
but if I want go to http://localhost:8000/about I get error:
Cannot GET /about
What should I do to make it well configured ?
Of course my react app, works fine with such link using in development start.
EDIT:
"scripts": {
"clean": "rimraf dist",
"compile": "node build/scripts/compile",
"build": "npm run clean && cross-env NODE_ENV=production npm run compile",
"start": "cross-env NODE_ENV=development node build/scripts/start",
"start:production": "cross-env NODE_ENV=production node build/scripts/start",
"test": "cross-env NODE_ENV=test karma start build/karma.config",
"test:watch": "npm test -- --watch",
"lint": "eslint .",
"lint:fix": "npm run lint -- --fix"
},
looks like my start:production is not good..