Attempting to build a Docker image for a Node.js app leads to an npm error: ‘Tracker uniqueTree already exists.’ My project consists of server.js, package.json, and a Dockerfile. Any tips?
// server.js
const http = require('http');
const srv = http.createServer((req, res) => {
res.end('Greetings from the server!');
});
srv.listen(3000, () => console.log('Server is live on port 3000'));
{
"dependencies": {
"http": "*"
},
"scripts": {
"run": "node server.js"
}
}
FROM node:16-alpine
WORKDIR /app
COPY package.json ./
RUN npm install
COPY . .
CMD ["npm", "run", "run"]
I encountered a similar error when developing a Node.js container. In my case, the problem was due to having a dependency entry that is unnecessary because the http module is built into Node. Removing it from the package.json avoided a conflict during the npm install process. Additionally, clearing the npm cache before running a clean docker build helped in eliminating any residual issues from previous builds. I recommend verifying that only required packages are listed in dependencies and conducting a local test to ensure consistency before rebuilding your Docker image.
hey, i think its about duplicate dep entries. try removin the unecessary http in your package.json and clean your package-lock before docker build. sometimes a fresh install fixes these errors.