Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Payload CLI Cannot find module

default discord avatar
broccoli_schorschlast year
6

I just updated to Payload 2 and get an error when I'm trying to use the payload cli (ex:

npm run payload migrate:create --file @payloadcms/db-mongodb/versions-v1-v2

or

npm run payload generate:types

Compiler doesn't find index.js files anymore. Any ideas?



Here is the output i get:


PAYLOAD_CONFIG_PATH=./payload.config.ts payload migrate:create @payloadcms/db-mongodb/versions-v1-v2

node:internal/modules/cjs/loader:995
  const err = new Error(message);
              ^

Error: Cannot find module '../fields/FieldRichText/index.js'
Require stack:
- /workspaces/payload-cms-template/packages/website/payload/blocks/BlockRichText.ts
- /workspaces/payload-cms-template/packages/website/payload/collections/CollectionNews.ts
- /workspaces/payload-cms-template/packages/website/payload.config.ts
- /workspaces/payload-cms-template/node_modules/payload/dist/config/load.js
- /workspaces/payload-cms-template/node_modules/payload/dist/bin/generateGraphQLSchema.js
- /workspaces/payload-cms-template/node_modules/payload/dist/bin/index.js
- /workspaces/payload-cms-template/node_modules/payload/bin.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:995:15)
    at Module._load (node:internal/modules/cjs/loader:841:27)
    at Module.require (node:internal/modules/cjs/loader:1061:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (/workspaces/payload-cms-template/packages/website/payload/blocks/BlockRichText.ts:12:61)
    at Module._compile (node:internal/modules/cjs/loader:1159:14)
    at Module._compile (/workspaces/payload-cms-template/node_modules/pirates/lib/index.js:117:24)
    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
    at Object.newLoader [as .ts] (/workspaces/payload-cms-template/node_modules/pirates/lib/index.js:121:7)
    at Module.load (node:internal/modules/cjs/loader:1037:32) {
  code: 'MODULE_NOT_FOUND',
  ...
}

Node.js v18.12.1
  • discord user avatar
    denolfe
    last year
    PAYLOAD_CONFIG_PATH=./payload.config.ts payload migrate:create @payloadcms/db-mongodb/versions-v1-v2

    This is missing

    --file

    does adding that back make a difference?

  • default discord avatar
    broccoli_schorschlast year

    Oh this was a copy-paste mistake.. i also get the error if i try to generate the types (

    npm run payload generate:types

    ). Does the payload CLI use the default tsconfig.json in the folder? We have to separate tsconfig files, one for next.js and one for payload

  • discord user avatar
    denolfe
    last year

    The default unless specified otherwise.

  • default discord avatar
    broccoli_schorschlast year

    how can i specify another config?

  • discord user avatar
    denolfe
    last year

    tsc can accept a

    --project

    switch, change that in your npm script

  • default discord avatar
    broccoli_schorschlast year

    Alight, thanks a lot for your help


    I'll give it a try next week



    The problem wasn't directly related to the payload upgrade. It was caused by a second version of

    @swc/core

    (

    1.3.82

    ) being installed by another dependency.

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.