Nobody, please? Can't figure it out 😦
With these standard scripts:
"scripts": {
"dev": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts nodemon",
"build:payload": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload build",
"build:server": "tsc",
"build": "yarn copyfiles && yarn build:payload && yarn build:server",
"serve": "cross-env PAYLOAD_CONFIG_PATH=dist/payload.config.js NODE_ENV=production node dist/server.js",
"copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png}\" dist/",
"generate:types": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload generate:types",
"generate:graphQLSchema": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload generate:graphQLSchema"
},
This Dockerfile:
FROM node:18-alpine as base
FROM base as builder
WORKDIR /app
COPY . .
RUN yarn install
RUN yarn build
FROM base as runtime
ENV NODE_ENV=production
WORKDIR /app
COPY package*.json ./
RUN yarn install --production
COPY --from=builder /app ./dist
COPY --from=builder /app ./build
EXPOSE 3000
CMD ["node", "dist/server.js"]
And this Compose file:
version: '3'
services:
payload:
ports:
- "3000:3000"
build: .
depends_on:
- mongo
environment:
MONGODB_URI: mongodb://mongo:27017/payload
PORT: 3000
networks:
- network
mongo:
image: mongo:latest
ports:
- "27017:27017"
command:
- --storageEngine=wiredTiger
volumes:
- data:/data/db
logging:
driver: none
networks:
- network
volumes:
data:
networks:
network:
name: traefik-network
I should be able to get it working. The Payload config is located at
src/payload.config.ts
, however this error occurs:
#0 3.786 Error: Error: can't find the configuration file located at /app/src/payload.config.ts.
#0 3.786 at build (/app/node_modules/payload/dist/bin/build.js:35:15)
Both Dockerfile and Compose file are located at the root, I run the build with
docker compose up
, the Dockerfile uses Node as base, then the builder stage happens, where everything is copied and builded, but that's where the error happens, and it doesn't make any sense why that happens. I ignore everything in
dockerignore
that isn't needed at first, like
node_modules, dist and build
folders
The build:payload script has a correct file path to the Payload config
Happens when running it in Docker on Linux and Windows
These are the contents of the image before build happens, everything looks OK
These are the contents of the image before
yarn install
happens
I'm done, the problem was that import for one utility had uppercase
URL
in it, while the correct path was
Url
. Because Windows doesn't care about uppercase / lowercase, it worked just fine, but Linux doesn't care and the build will then throw an error.
On the other hand, Payload reported a false positive (false error) about the config file because in this block:
export const build = async (): Promise<void> => {
try {
const config = await loadConfig();
const webpackProdConfig = getWebpackProdConfig(config);
webpack(webpackProdConfig, (err, stats) => { // Stats Object
if (err || stats.hasErrors()) {
// Handle errors here
if (stats) {
console.error(stats.toString({
chunks: false,
colors: true,
}));
} else {
console.error(err.message);
}
}
});
} catch (err) {
console.error(err);
throw new Error(`Error: can't find the configuration file located at ${rawConfigPath}.`);
}
};
It somehow catched the import error and throwed a new error with the message below which was misleading
throw new Error(`Error: can't find the configuration file located at ${rawConfigPath}.`);
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.