Payload CLI Cannot find module

default discord avatar
broccoli_schorsch
4 weeks ago
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
    Payload Team
    4 weeks ago
    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_schorsch
    4 weeks ago

    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
    Payload Team
    4 weeks ago

    The default unless specified otherwise.

  • default discord avatar
    broccoli_schorsch
    4 weeks ago

    how can i specify another config?

  • discord user avatar
    denolfe
    Payload Team
    4 weeks ago

    tsc can accept a

    --project

    switch, change that in your npm script

  • default discord avatar
    broccoli_schorsch
    4 weeks ago

    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.

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.