Import module error in payload.config.ts while starting Payload #7415
Unanswered
ckerimoglu
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am trying to incorporate PayloadCMS into my existing Next 13 (app router) project. I have followed the documentation and installed Payload with
npm install --save --legacy-peer-deps payload
. The version that I have installed is, per package.json file the following:"payload": "^2.25.0"
.I have also created server.ts and payload.config.ts files as described in documentation and put them into my root folder. However, when I try to start payload using
node --loader ts-node/esm server.ts
I get the error below.To preempt some legitimate questions that may arise, the reason I didn’t use
ts-node server.ts
was because this command wasn’t recognizing .ts files and this turned out to be an issue of Node 20, which I am using (Node.js v20.16.0). But anyway, the command itself seems to execute normally and the payload.config.ts file is being recognized. But for some reason, I am getting this module error, although my package.json does have"type": "module"
, and I'm using import syntax everywhere else just fine. Here is the relevant part of my package.json file:Just in case, here are also my server.ts and payload.config.ts files.
./server.ts
./payload.config.ts
Moreover, I notice that the error message tracks down to some files which are inside node_modules and were created there automatically after payload was installed. Here is the load.js file for example which is under /node_modules/payload/dist/config/
I can see that it is using “require” syntax, instead of import. Should I even touch it and other files that appear in the error message? They also use "require" syntax. The alternative – i.e., removing
“type”: “module”
from package.json and trying to use “require” syntax everywhere made things even worse, giving rise to plenty other errors, since I have been using “import” syntax throughout my project. And anyway, in the example template repositories provided in Payload Github page all the files are using “import” syntax just as I am doing. Why am I getting this error? Can it be with the Payload version? Or something else? I would greatly appreciate your help, as this has been driving me crazy for several days now.Beta Was this translation helpful? Give feedback.
All reactions