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.

NextJS Custom Server - Error resolving module

default discord avatar
enrico.bagattin2 years ago
5

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
    notchr2 years 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.bagattin2 years 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

  • discord user avatar
    jarrod_not_jared
    2 years 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.bagattin2 years 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

  • discord user avatar
    jarrod_not_jared
    2 years ago

    Oh awesome! 😅😅

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.