I get Error: Cannot find module '/usr/src/nuxt-app/nuxt' when I try to run app on the server. i didn't change anything in dockerfile or circleci config. it had been working before, i don't know what happened. Image is build by circleci. Locally without using docker everything works as it should. What do I do with it?
Error:
throw err;
^
Error: Cannot find module '/usr/src/nuxt-app/nuxt'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
at Function.Module._load (internal/modules/cjs/loader.js:725:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at internal/main/run_main_module.js:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
Dockerfile:
FROM node:lts-alpine
RUN mkdir -p /usr/src/nuxt-app
WORKDIR /usr/src/nuxt-app
RUN apk update && apk upgrade
RUN apk add python make g++
ADD . /usr/src/nuxt-app/
RUN npm install
RUN npm run build
EXPOSE 5002
CMD [ "nuxt", "start" ]
circleci config.yml:
version: 2.1
orbs:
docker: circleci/docker#1.5.0
node: circleci/node#4.1.0
workflows:
build-deploy:
jobs:
- deploy:
context:
- docker
requires:
- build
filters:
branches:
only: master
jobs:
deploy:
machine: true
steps:
- checkout
- docker/install-docker-tools
- run:
name: Login to Docker
command: docker login -u=$DOCKER_LOGIN -p=$DOCKER_PASSWORD registry.xxx.com
- docker/build:
image: yyy
registry: registry.xxx.com
tag: latest
- docker/push:
image: yyy
registry: registry.xxx.com
tag: latest
Related
My build and deployment just suddenly stopped working for no reason. It was working a few months ago but now it is failing. Below is the error message.
ERROR in ./src/styles/global.scss
Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):
ModuleBuildError: Module build failed (from ./node_modules/sass-loader/lib/loader.js):
Error: Cannot find module 'node-sass'
at Function.Module._resolveFilename (module.js:536:15)
at Function.Module._load (module.js:466:25)
at Module.require (module.js:579:17)
at require (internal/module.js:11:18)
at Object.sassLoader (/opt/atlassian/pipelines/agent/build/node_modules/sass-loader/lib/loader.js:46:72)
This is the snippet of my bitbucket-pipelines.yml
image: node:8.9.0
pipelines:
branches:
master: # Build and deploy master branch
- step:
caches:
- node
script:
- sh publish_version.sh
- npm install
- npm run build_production
artifacts:
- dist/**
- step:
name: Deploy to S3
deployment: production
image: atlassian/pipelines-awscli
script: # Copy to S3
- pwd
- aws s3 sync --delete dist s3://production.mysite.com
This is the snippet of my bitbucket-pipelines.yml
This is what npm run build_production is :
"build_production": "ng build --production --output-path=dist"
According to node-sass github page, the supported node.js versions vary release by release.
Note: If you are using any background-url in src/styles/global.scss then make sure that the image must be in /asset folder with the relevant directory time if the image is not available then also this error will be thrown by angular.
I'm using Docker Desktop and I'm working with a Nest.js app, when I build my project with docker-compose build everything is fine since there are no errors in console, however when I run docker-compose up -d my container keeps on failing because it can't find the build directory of my app. The strange thing is that this works perfectly fine in my Windows computer, but my macOS laptop is the one that's failing
Error: Cannot find module '/tmp/dist/main'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:885:15)
at Function.Module._load (internal/modules/cjs/loader.js:730:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at internal/main/run_main_module.js:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
This is my dockerfile:
FROM node:14.17.0-alpine
WORKDIR /tmp
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
EXPOSE 3005
ENV NODE_TLS_REJECT_UNAUTHORIZED=0
# Run it
ENTRYPOINT ["node", "/tmp/dist/main"]
This is my docker-compose file and the folder structure of the project is pretty basic, after I run the npm run build command a dist folder is created at the root of my project.
version: '3'
services:
my-api:
build: ./my-api
container_name: 'my-api'
restart: always
environment:
NODE_ENV: "docker-compose"
APP_PORT: 3005
ports:
- "3005:3005"
- 9229:9229
depends_on:
- redis
- mysql
As you set WORKDIR /tmp you are currently executing commands in this directory. https://docs.docker.com/engine/reference/builder/#workdir
And from what you provided there is no another tmp directory in you current working directory.
Try to change last command to
ENTRYPOINT ["node", "/dist/main"]
I have developed an application in node js that needs to connect to MongoDB because of that I implemented a wait-for.sh script, when I run the entire application in my computer docker everything goes well, but when I run it in my digital ocean ubuntu 20.04 server it crashed with the following error
Node.js v17.4.0
/usr/app/wait-for.sh:3
# original script: https://github.com/eficode/wait-for/blob/master/wait-for
^
SyntaxError: Invalid or unexpected token
at Object.compileFunction (node:vm:352:18)
at wrapSafe (node:internal/modules/cjs/loader:1026:15)
at Module._compile (node:internal/modules/cjs/loader:1061:27)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1149:10)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47
This is the dockerfile
FROM node:17-alpine
WORKDIR /usr/app
COPY package.json .
RUN npm install --quiet
COPY . .
COPY wait-for.sh wait-for.sh
RUN chmod +x wait-for.sh
# Deleting windows characteres
RUN apt-get install -y dos2unix # Installs dos2unix Linux
RUN find . -type f -exec dos2unix {} \; # recursively removes windows related stuff
The docker compose
version: '3.3'
services:
monitor:
build:
context: .
dockerfile: Dockerfile
container_name: app
restart: unless-stopped
volumes:
- .:/usr/app/
- /usr/app/node_modules
networks:
- app-network
command: ./wait-for.sh db:27017 -- node index.js
db:
image: mongo
container_name: db
restart: unless-stopped
volumes:
- dbdata:/data/db
networks:
- app-network
networks:
app-network:
driver: bridge
volumes:
dbdata:
node_modules:
And the wait for link
wait for script
I don't know why is this happening
Here is my Dockerfile which is at the root of the nodejs application.
# Build from LTS version of node (version 12)
FROM node:12
# Create app directory
RUN mkdir -p /usr/src/app
# Define app diretory inside image
WORKDIR /usr/src/app
# package.json AND package-lock.json are copied where available
COPY package*.json /usr/src/app/
# install modules
RUN npm install
# Bundle app source
COPY . /usr/src/app
# Bind app to port 3000
EXPOSE 3000
# Command to run app
CMD [ "nodemon", "./bin/www" ]
Here is my docker-compose.yml file
version: '2'
services:
mongo:
container_name: mongo
image: 'mongo:3.4.1'
ports:
- "27017:27017"
backend-app:
container_name: school-backend
restart: always
build: ./server
ports:
- "3000:3000"
frontend-app:
container_name: angular-frontend
restart: always
build: ./angular-app
ports:
- "4200:4200"
I execute the command docker-compose up
Then I get this error
school-backend | Error: Cannot find module '/usr/src/app/nodemon'
school-backend | at Function.Module._resolveFilename (internal/modules/cjs/loader.js:966:15)
school-backend | at Function.Module._load (internal/modules/cjs/loader.js:842:27)
school-backend | at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
school-backend | at internal/main/run_main_module.js:17:47 {
school-backend | code: 'MODULE_NOT_FOUND',
school-backend | requireStack: []
school-backend | }
In the Dockerfile, I copy the package.json to the working directory /usr/src/app\.
Then I do npm install which would install nodemon since it is declared in the package.json
But, why is the module given as absent?
It's not globally installed then.
In this case, you have to call the nodemon bin inside the node_modules: ./node_modules/nodemon/bin/nodemon.js.
You can use npx like this CMD [ "npx", "nodemon", "./bin/www" ].
npx will run programs from the node_modules/.bin directory.
I'm working on automation of following build steps:
- building frontend application with webpack
- running tests on it
I am using Jenkins with blue-ocean plugin enabled, here is Jenkinsfile:
Jenkinsfile:pipeline {
agent {
dockerfile {
filename 'Dockerfile'
}
}
stages {
stage('Build') {
steps {
sh 'npm run build'
}
}
}
}
I'm using following Dockerfile
FROM node:latest
WORKDIR /app
COPY . /app
RUN npm install webpack -g && npm install
The problem is that when running npm run build it can not find webpack:
> webpack --config webpack-production.config.js --progress --colors
module.js:529
throw err;
^
Error: Cannot find module 'webpack'
at Function.Module._resolveFilename (module.js:527:15)
at Function.Module._load (module.js:476:23)
at Module.require (module.js:568:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/var/lib/jenkins/workspace/l-ui-webpack-example_master-IXSLD4CQSVAM2DRFHYHOYUANEHJ73R5PUGW4BMYVT5WPGB6ZZKEQ/webpack-production.config.js:1:79)
It looks like commands are being executed in host context, not on container as manual running works just fine:
docker build . -t sample
docker run sample npm run build
Here is full jenkins log:Jenkins build log
Here is a link to a repository: Source code
I had exactly the same issue. For some reason, 'RUN npm install' within the Dockerfile didn't take effect in the Jenkins pipeline although it worked well when I built the image manually.
I got the pipeline working by running "npm install" as a step in the pipeline. So add this to your Jenkinsfile before the 'Build' stage:
stage ('install app') {
steps {
sh "npm install"
}
}
I don't know why this happens but it might have something to do with how Jenkins sets the context for the Docker build. I hope someone else can elaborate on this.