Hi, I have the following error when I try to run the
payload generate:typescommand.
➜ payload generate:types
node:internal/modules/package_json_reader:268
throw new ERR_MODULE_NOT_FOUND(packageName, fileURLToPath(base), null);
^
Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@/contents' imported from /Users/itslame/Documents/repos/itslame/src/payload.config.ts
at Object.getPackageJSONURL (node:internal/modules/package_json_reader:268:9)
at packageResolve (node:internal/modules/esm/resolve:768:81)
at moduleResolve (node:internal/modules/esm/resolve:854:18)
at defaultResolve (node:internal/modules/esm/resolve:984:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:685:12)
at #cachedDefaultResolve (node:internal/modules/esm/loader:634:25)
at ModuleLoader.getModuleJobForRequire (node:internal/modules/esm/loader:384:53)
at new ModuleJobSync (node:internal/modules/esm/module_job:341:34)
at ModuleLoader.importSyncForRequire (node:internal/modules/esm/loader:357:11)
at loadESMFromCJS (node:internal/modules/cjs/loader:1385:24) {
code: 'ERR_MODULE_NOT_FOUND'
}
Node.js v22.14.0I decided to run this command because I noticed that my
payload-types.tsfile is not auto-generated when I added new fields in my collection. Not sure what happened because it worked fine so far and I've not added/updated any packages.
you may need to add
"paths": {
"@/*": ["./src/*"],to your tsconfig
your issue is with @/components path resolution
yup I already have this path alias setup and it's working throughout the project
share your repo, or folder structure and tsconfig content.
i have a lot of these issues in a large monorepo so should be able to help
my folder structure current looks like this
tsconfig.json
{
"compilerOptions": {
"target": "ES2017",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": [
"./src/*"
],
"@payload-config": [
"./src/payload.config.ts"
]
}
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts"
],
"exclude": [
"node_modules"
]
}for further context i tried importing via "./" (without alias) and was still faced with a similar error:
payload generate:types
node:internal/modules/esm/resolve:275
throw new ERR_MODULE_NOT_FOUND(
^
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/Users/itslame/Documents/repos/itslame/src/contents/collections/Users' imported from /Users/itslame/Documents/repos/itslame/src/payload.config.tsin your
{
"compilerOptions": {
/* Strictness */
"strict": true,
"noUncheckedIndexedAccess": true,
"noImplicitOverride": true,
"baseUrl": ".",
"esModuleInterop": true,
"target": "ES2022",
"lib": ["DOM", "DOM.Iterable", "ES2022"],
"allowJs": true,
"skipLibCheck": true,
"strictNullChecks": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"incremental": true,
"jsx": "preserve",
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"sourceMap": true,
"isolatedModules": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@payload-config": ["./src/payload.config.ts"],
"react": ["./node_modules/@types/react"],
"@/*": ["./src/*"]
}
},
"include": [
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts",
"redirects.js",
"next.config.js",
"next-sitemap.config.cjs",
"payload.config.ts"
],
"exclude": ["node_modules"]
}here is mine from my base create-payload-app website tempalte
try and copy exactly, see if you have the same issue, could be one of the tsconfig props here like baseUrl
i think you need to set baseurl and paths, paths use the baseurl as the reference so @/components = ../src/components, but atm it doesnt know to link @ to ./
just tried copy pasting ur config and still the same error :c
i just dont quite get why this throws out an error too even when given absolute path
paste your package.json
do you have "type": "module", set
this seemed to do the trick!
payload generate:types
[23:39:53] INFO: Compiling TS types for Collections and Globals...
[23:39:53] INFO: Types written to /Users/itslame/Documents/repos/itslame/src/payload-types.tsnice!
btw what's the "type" field for
When you have "type": "module" in the package.json file, your source code should use import syntax. When you do not have, you should use require syntax; that is, adding "type": "module" to the package.json enables ES 6 modules. For more info, see here.
oh i see got it thanks!
use
/solveto solve this thread if complete
no problem!
oh didn't know that
🙂
Star
Discord
online
Get dedicated engineering support directly from the Payload team.