NextJS Custom Server - Error resolving module

default discord avatar
Enrico
8 months ago
7

Hello, maybe someone could help, I am developing a project based on this boilerplate:

https://github.com/payloadcms/nextjs-custom-server

I I build and serve the project I get

MODULE_NOT_FOUND

error when trying to import my custom view in a payload collection.



Here is the output:


yarn run v1.22.19
$ cross-env NODE_ENV=production PAYLOAD_CONFIG_PATH=dist/payload.config.js node dist/server.js
[10:01:54] INFO (payload): Connected to Mongo server successfully!
[10:01:54] INFO (payload): Starting Payload...
unhandledRejection Error: Cannot find module '../components/CustomMinimalView'
Require stack:
- /dist/collections/Page.js
- /dist/payload.config.js
- /node_modules/payload/dist/config/load.js
- /node_modules/payload/dist/payload.js
- /node_modules/payload/dist/initHTTP.js
- /node_modules/payload/dist/index.js
- /dist/server.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:985:15)
    at Function.mod._resolveFilename (/node_modules/next/dist/build/webpack/require-hook.js:23:32)
    at Function.Module._load (node:internal/modules/cjs/loader:833:27)
    at Module.require (node:internal/modules/cjs/loader:1057:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (/dist/collections/Page.js:11:43)
    at Module._compile (node:internal/modules/cjs/loader:1155:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1209:10)
    at Module.load (node:internal/modules/cjs/loader:1033:32)
    at Function.Module._load (node:internal/modules/cjs/loader:868:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/dist/collections/Page.js',
    '/dist/payload.config.js',
    '/node_modules/payload/dist/config/load.js',
    '/node_modules/payload/dist/payload.js',
    '/node_modules/payload/dist/initHTTP.js',
    '/node_modules/payload/dist/index.js',
    '/dist/server.js'
  ]
}
  • default discord avatar
    thisisnotchris
    8 months ago

    That would mean the path to the imported module is not correct I believe



    Can you confirm that

    '../components/CustomMinimalView'

    is correct

  • default discord avatar
    Enrico
    8 months ago

    That's correct, I forgot to write that running the dev script it works, this problem only came up on compiled files. I also verified that the file is included in the build and it is

  • default discord avatar
    Jarrod
    7 months ago

    ahhhh I was talking to someone in another thread with the same issue. I will try to find and tag it here, it was also un resolved, but will be nice to tie them together.



    NextJS Custom Server - Error resolving module

  • default discord avatar
    Enrico
    7 months ago

    Yes, we solved this in Github, here it is:

    https://github.com/payloadcms/nextjs-custom-server/issues/30

    The tsconfig file was missing the jsx option

  • default discord avatar
    Jarrod
    7 months ago

    Oh awesome! 😅😅

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.