Im having a really bad experience with payload. I have made a nextjs app with payload but couldnt deploy it on railway together. Today ive separated the apps into two (i ve created payload with create-payload-app) and i could deploy the backend to railway but if i add any dependency i get one unmet peer dependency warning after another... after installing the dependencies i get
/node_modules/cliui/build/index.cjs:291
const stringWidth = require('string-width');
^
Error [ERR_REQUIRE_ESM]: require() of ES ModuleIm late 1 week because of the constant problems
Railway log
warning Pattern ["string-width@^4.1.0"] is trying to unpack in the same destination "/usr/local/share/.cache/yarn/v6/npm-string-width-cjs-4.2.3-269c7117d27b05ad2e536830a8ec895ef9c6d010-integrity/node_modules/string-width-cjs" as pattern ["string-width-cjs@npm:string-width@^4.2.0"]. This could result in non-deterministic behavior, skipping.error next@14.0.5-canary.46: The engine "node" is incompatible with this module. Expected version ">=18.17.0". Got "18.8.0"I dont have next installed
Hey
@807013297680547840have you taken a look at this?
https://payloadcms.com/community-help/discord/trying-to-deploy-to-railway-what-am-i-missingHello i have fixed this problem at the beginning when ive tested with a blank payload app. Now the problem is that i cant even build it not even locally. It does not get past of the copyfiles script
can you share the errors you are getting now if not the above?
This is the build log locally (i have removed the username and project folder from the paths)
yarn build
yarn run v1.22.21
$ yarn copyfiles && yarn build:payload && yarn build:server
$ copyfiles -u 1 "src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png}" dist/
.../node_modules/cliui/build/index.cjs:293
const wrap = require('wrap-ansi');
^
Error [ERR_REQUIRE_ESM]: require() of ES Module .../node_modules/wrap-ansi/index.js from .../node_modules/cliui/build/index.cjs not supported.
Instead change the require of index.js in .../node_modules/cliui/build/index.cjs to a dynamic import() which is available in all CommonJS modules.
at Object.<anonymous> (.../node_modules/cliui/build/index.cjs:293:14)
at Object.<anonymous> (.../node_modules/yargs/build/index.cjs:2861:12)
at Object.<anonymous> (.../node_modules/yargs/index.cjs:5:30)
at Object.<anonymous> (.../node_modules/copyfiles/copyfiles:4:12) {
code: 'ERR_REQUIRE_ESM'
}
Node.js v20.8.0
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.And this is the build log on railway
#10 1.723 warning Pattern ["string-width@^4.1.0"] is trying to unpack in the same destination "/usr/local/share/.cache/yarn/v6/npm-string-width-cjs-4.2.3-269c7117d27b05ad2e536830a8ec895ef9c6d010-integrity/node_modules/string-width-cjs" as pattern ["string-width-cjs@npm:string-width@^4.2.0"]. This could result in non-deterministic behavior, skipping.
#11 1.395 warning Pattern ["wrap-ansi@^7.0.0"] is trying to unpack in the same destination "/usr/local/share/.cache/yarn/v6/npm-wrap-ansi-cjs-7.0.0-67e145cff510a6a6984bdf1152911d69d2eb9e43-integrity/node_modules/wrap-ansi-cjs" as pattern ["wrap-ansi-cjs@npm:wrap-ansi@^7.0.0"]. This could result in non-deterministic behavior, skipping.
#11 54.23 error next@14.0.5-canary.46: The engine "node" is incompatible with this module. Expected version ">=18.17.0". Got "18.8.0"
ERROR: failed to solve: process "/bin/sh -c yarn install --production" did not complete successfully: exit code: 1these are the dependencies
"dependencies": {
"@payloadcms/bundler-webpack": "^1.0.0",
"@payloadcms/db-mongodb": "^1.0.0",
"@payloadcms/richtext-slate": "^1.0.0",
"@react-email/components": "^0.0.14",
"@react-email/render": "^0.0.12",
"cors": "^2.8.5",
"cross-env": "^7.0.3",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"payload": "^2.0.0",
"react": "^18.2.0",
"react-email": "^2.0.0"
},
"devDependencies": {
"@types/express": "^4.17.9",
"copyfiles": "^2.4.1",
"nodemon": "^2.0.6",
"ts-node": "^9.1.1",
"typescript": "^4.8.4"
}The local dev server starts without an issue i can query and createa data, and send email, the only change is that i have added a few depdenecies like cors and react email
I've installed the dependencies one by one and tested the build command after each, i've found out that adding @react-email/components causes the problem
node_modules/cliui/build/index.cjs:291
const stringWidth = require('string-width');and removing it does not fix the problem
I’m having the same issues with payload 2 as well. It’s been quite annoying; I’ve just put projects on hold, as opposed to deploying. I’ve never had these sort of issues deploying something… and I’m just trying to deploy it with docker.
I haven’t posted anything, because I see multiple mentions of such issues, but still awaiting any sort of resolution.
and removing it does not fix the problem
is this true even if you delete the
node_modules/.cachefolder and any other similar build/cache folders?
can you get this code in a repo and we can take a look tomorrow and see if its an issue with a specific package or an upstream issue where we might have to pin versions which has happened before when
esmerrors come out of the blue
In my instance, I do not have
@react-email/components, or anything to do with react-email installed, nor has it ever been installed in my project. I believe the issue to be with
copyfiles@132273173847736320
I have deleted the node_modules folder completely and after resintalling it without all the react-email dependencies, it built the app succesfully both locally and on railway. Maybe it overwritten some files? I need to find an alternative for email templating, if you have suggestions feel free to share. I will create a repo for you soon.
So i was going to create the repo but, its really not hard to replicate.
1. npx create-payload-app
2. yarn add @react-email/components
It installs with a lot of peer dependency warnings
3. yarn build
Now it has built it succesfully now, wtf...
4. yarn add @react-email/render
5. yarn build
The error occurs
If for some reason it doest work for you ( or should i say does work ) i will create a repo.
this suggests to me a dependency resolution issue, pinning the versions of react-email packages to something previous should fix it or pinning the underlying package, ill have a look later today and see if its anything obvious
other than react-email the other one I know of (and is a fork of react email) is
https://jsx.email/not sure if it might have the same issue
This is not a Payload issue. It is a yarn v1 dependency resolution issue.
Yarn 2+, npm, and pnpm all resolve @react-email depdendencies properly.
More detail here:
https://github.com/yarnpkg/yarn/issues/4812TLDR, use Yarn 2+ or another package manager.
Unfortunately, this is just node ecosystem growth pains.
Thanks for the alternative and explanation!
I switched over to pnpm and got rid of those errors, however, I keep getting an error related to cross-env now?
#0 1.114 > cross-env NODE_ENV=production pnpm run build:payload && pnpm run build:server && pnpm run copyfiles && pnpm run build:next
#0 1.114
#0 1.158 node:internal/modules/cjs/loader:1080
#0 1.158 throw err;
#0 1.158 ^
#0 1.158
#0 1.158 Error: Cannot find module '/home/node/app/node_modules/cross-env/src/bin/cross-env.js'
#0 1.158 at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)
#0 1.158 at Module._load (node:internal/modules/cjs/loader:922:27)
#0 1.158 at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
#0 1.158 at node:internal/main/run_main_module:23:47 {
#0 1.158 code: 'MODULE_NOT_FOUND',
#0 1.158 requireStack: []
#0 1.158 }
#0 1.158
#0 1.158 Node.js v18.17.1
#0 1.164 ELIFECYCLE Command failed with exit code 1.
------
failed to solve: process "/bin/sh -c pnpm run build" did not complete successfully: exit code: 1package.json has
cross-env@7.0.3, just as the website template and my build script looks like this;
"build": "cross-env NODE_ENV=production pnpm run build:payload && pnpm run build:server && pnpm run copyfiles && pnpm run build:next",Perhaps I've done something wrong with the Dockerfile?
FROM node:18.17-alpine as base
# Install pnpm globally
RUN apk add --no-cache curl && \
curl -f https://get.pnpm.io/v6.16.js | node - add --global pnpm
# Set up pnpm store
ENV PNPM_STORE_DIR /home/node/.pnpm-store
ENV PNPM_STORE_ENGINE=v3
FROM base as builder
WORKDIR /home/node/app
# Copying only package files to cache dependencies
COPY package*.json ./
# If you have a pnpm-lock.yaml, you should copy it as well
COPY pnpm-lock.yaml ./
# Install dependencies and build your app
COPY . .
RUN pnpm install
RUN pnpm run build
FROM base as runtime
ENV NODE_ENV=production
ENV PAYLOAD_CONFIG_PATH=dist/payload.config.js
WORKDIR /home/node/app
COPY package*.json ./
COPY pnpm-lock.yaml ./
# Install only production dependencies
RUN pnpm install --prod
# Copy the built artifacts from the builder stage
COPY --from=builder /home/node/app/dist ./dist
COPY --from=builder /home/node/app/build ./build
COPY --from=builder /home/node/app/.next ./.next
EXPOSE 3000
CMD ["node", "dist/server.js"]Star
Discord
online
Get dedicated engineering support directly from the Payload team.