You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I get some dependency issues when using the localAPI in a Sveltekit application. I tried using it like so:
// payload-client.tsimport{typeBasePayload,getPayload,typeGeneratedTypes}from'payload';import{importConfig}from'payload/node';import'dotenv/config';importpathfrom'node:path';import{fileURLToPath}from'node:url';letpayloadInstance: BasePayload<GeneratedTypes>;// payload-client.tsexportasyncfunctioninitializePayload(){const__dirname=path.dirname(fileURLToPath(import.meta.url));constpayloadConfigPath=path.join(__dirname,'./payload/payload.config.ts');constawaitedConfig=awaitimportConfig(payloadConfigPath);payloadInstance=awaitgetPayload({config: awaitedConfig});}exportasyncfunctiongetPayloadInstance(){if(!payloadInstance){thrownewError('Payload has not been initialized. Call initializePayload first.');}returnpayloadInstance;}
Running it locally works just fine, both using pnpm dev and making a production build with pnpm buildpnpm serve... however deploying it to vercel gives the following error:
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/var/task/node_modules/.pnpm/payload@3.0.0-beta.35_@swc+core@1.5.7_@swc+helpers@0.5.11__@swc+types@0.1.7_graphql@16.8.1_typescript@5.4.5/node_modules/payload/dist/bin/loader/index.js' imported from /var/task/.svelte-kit/output/server/entries/pages/payload/payload.config.ts
at finalizeResolution (node:internal/modules/esm/resolve:269:11)
at moduleResolve (node:internal/modules/esm/resolve:937:10)
at moduleResolveWithNodePath (node:internal/modules/esm/resolve:1161:14)
at defaultResolve (node:internal/modules/esm/resolve:1204:79)
at nextResolve (node:internal/modules/esm/hooks:866:28)
at Hooks.resolve (node:internal/modules/esm/hooks:304:30)
at ModuleLoader.resolve (node:internal/modules/esm/loader:352:35)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:234:38)
at ModuleLoader.import (node:internal/modules/esm/loader:322:34)
at Hooks.register (node:internal/modules/esm/hooks:165:51) {
code: 'ERR_MODULE_NOT_FOUND',
url: 'file:///var/task/node_modules/.pnpm/payload@3.0.0-beta.35_@swc+core@1.5.7_@swc+helpers@0.5.11__@swc+types@0.1.7_graphql@16.8.1_typescript@5.4.5/node_modules/payload/dist/bin/loader/index.js'
}
I tried both inside a turborepo and in a separate project without turborepo. Both failed with similar errors. The error above is from the non-turborepo version, and this error is from the turborepo:
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/var/task/node_modules/.pnpm/payload@3.0.0-beta.32_@swc+core@1.5.7_@swc+types@0.1.7_graphql@16.8.1_typescript@5.4.5/node_modules/payload/dist/bin/loader/index.js' imported from /var/task/apps/web/.svelte-kit/output/cms/src/payload.config.ts
at finalizeResolution (node:internal/modules/esm/resolve:269:11)
at moduleResolve (node:internal/modules/esm/resolve:937:10)
at moduleResolveWithNodePath (node:internal/modules/esm/resolve:1161:14)
at defaultResolve (node:internal/modules/esm/resolve:1204:79)
at nextResolve (node:internal/modules/esm/hooks:866:28)
at Hooks.resolve (node:internal/modules/esm/hooks:304:30)
at ModuleLoader.resolve (node:internal/modules/esm/loader:352:35)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:234:38)
at ModuleLoader.import (node:internal/modules/esm/loader:322:34)
at Hooks.register (node:internal/modules/esm/hooks:165:51) {
code: 'ERR_MODULE_NOT_FOUND',
url: 'file:///var/task/node_modules/.pnpm/payload@3.0.0-beta.32_@swc+core@1.5.7_@swc+types@0.1.7_graphql@16.8.1_typescript@5.4.5/node_modules/payload/dist/bin/loader/index.js'
}
Deploy both the cms app and the web app as two separate vercel deployments.
Here's how the cms app should be deployed:
Replace the DATABASE_URI env with your connection string. If you're using neon that can be found in your dashboard. Make sure it's a pooled connection:
Here's how the web app should be deployed:
Remember to add the env vars here too.
Once it's all deployed it should all be green, but if you visit the url for your frontend (web), it should show a 500 internal error. And if you go to the logs in vercel you should be able to see the same error message as described in this issue.
If you want to test the simplified non-turborepo version:
If you wanna test it locally it's just cp .env.example .env, pnpm i and pnpm dev
deploy it to vercel using the default SvelteKit (v1) settings. Use the same DATABASE_URI as in the turborepo example
Go to the deployed website and notice that you get a 500 error here too. If you go to logs in vercel should see the same errors as shown in this issue.
Payload Version
beta (3.0.0-beta.34 as of the time this issue was posted)
Adapters and Plugins
db-postgres, lexical
The text was updated successfully, but these errors were encountered:
@Snailedlt my gut tells me that this is a limitation from Vercel. If you check out their docs related to root directory, they say that you cannot access files outside the root of your app.
It looks like you are trying to go up and out of your web app root dir and into another folder within your mono repo in this file.
Could you try copying the payload config into your web app directory and adjust your imports to go to that config file to test this theory?
they say that you cannot access files outside the root of your app.
Looks like it should have access to the files outside of the root:
I actually got an error about the file path to the config being wrong. After correcting it, it worked even though the file path is outside of the root of the app.
Could you try copying the payload config into your web app directory and adjust your imports to go to that config file to test this theory?
This is what I've done in the other repo I linked to at the bottom of the "To reproduce" section:
If you want to test the simplified non-turborepo version:
Follow all the steps from the turborepo version
fork my repo: https://github.com/Snailedlt/sveltekit-payload-frontend
If you wanna test it locally it's just cp .env.example .env, pnpm i and pnpm dev
deploy it to vercel using the default SvelteKit (v1) settings. Use the same DATABASE_URI as in the turborepo example
Go to the deployed website and notice that you get a 500 error here too. If you go to logs in vercel should see the same errors as shown in this issue.
Link to reproduction
https://sveltekit-payload-frontend.vercel.app/
Describe the Bug
I get some dependency issues when using the localAPI in a Sveltekit application. I tried using it like so:
Running it locally works just fine, both using
pnpm dev
and making a production build withpnpm build
pnpm serve
... however deploying it to vercel gives the following error:I tried both inside a turborepo and in a separate project without turborepo. Both failed with similar errors. The error above is from the non-turborepo version, and this error is from the turborepo:
Before I opened this issue I discussed it on Discord. The linked discord thread can be found here: https://discord.com/channels/967097582721572934/1238608849099948212
To Reproduce
In order to test the turborepo version:
cp .env.example .env
pnpm i
andpnpm dev
to start the cms and web projects. Create a new user in Payload (http://localhost:3000)pnpm build
andpnpm start
. This should work the same if done locally.Replace the
DATABASE_URI
env with your connection string. If you're using neon that can be found in your dashboard. Make sure it's a pooled connection:Remember to add the env vars here too.
If you want to test the simplified non-turborepo version:
cp .env.example .env
,pnpm i
andpnpm dev
Payload Version
beta (3.0.0-beta.34 as of the time this issue was posted)
Adapters and Plugins
db-postgres, lexical
The text was updated successfully, but these errors were encountered: