Path Alias Setup with tsconfig.json not working #3699
Replies: 9 comments
-
Hey @creative-andrew The problem is that we need to tell BOTH webpack AND ts-node to handle those paths as well. I've made a repo here which does that. It automatically adds the webpack aliases and uses the tsconfig-paths package with ts-node. We could probably add some of that functionality into payload to make configured tsconfig paths work automatically - but I'd say that's a feature request rather than an issue |
Beta Was this translation helpful? Give feedback.
-
@AlessioGr it worked fine in dev mode, but as soon as I do a build it complains: [13:43:50] INFO (payload): Connected to MongoDB server successfully!
[13:43:50] INFO (payload): Starting Payload...
node:internal/modules/cjs/loader:1075
const err = new Error(message);
^
Error: Cannot find module '@/fields/list'
Require stack:
- /home/node/app/backend/dist/blocks/TeaserPlanungsteam/index.js
- /home/node/app/backend/dist/collections/Pages.js
- /home/node/app/backend/dist/payload.config.js
- /home/node/app/backend/node_modules/payload/dist/config/load.js
- /home/node/app/backend/node_modules/payload/dist/payload.js
- /home/node/app/backend/node_modules/payload/dist/initHTTP.js
- /home/node/app/backend/node_modules/payload/dist/index.js
- /home/node/app/backend/dist/server.js
at Module._resolveFilename (node:internal/modules/cjs/loader:1075:15)
at Module._load (node:internal/modules/cjs/loader:920:27)
at Module.require (node:internal/modules/cjs/loader:1141:19)
at require (node:internal/modules/cjs/helpers:110:18)
at Object.<anonymous> (/home/node/app/backend/dist/blocks/TeaserPlanungsteam/index.js:8:30)
at Module._compile (node:internal/modules/cjs/loader:1254:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
at Module.load (node:internal/modules/cjs/loader:1117:32)
at Module._load (node:internal/modules/cjs/loader:958:12)
at Module.require (node:internal/modules/cjs/loader:1141:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/home/node/app/backend/dist/blocks/TeaserPlanungsteam/index.js',
'/home/node/app/backend/dist/collections/Pages.js',
'/home/node/app/backend/dist/payload.config.js',
'/home/node/app/backend/node_modules/payload/dist/config/load.js',
'/home/node/app/backend/node_modules/payload/dist/payload.js',
'/home/node/app/backend/node_modules/payload/dist/initHTTP.js',
'/home/node/app/backend/node_modules/payload/dist/index.js',
'/home/node/app/backend/dist/server.js'
]
} Do we need a special treatment for the |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
@AlessioGr Could this be supported in v2? |
Beta Was this translation helpful? Give feedback.
-
I ended up using tsc-alias as a workaround. tsconfig:
payload.config:
|
Beta Was this translation helpful? Give feedback.
-
I ended up doing the same and it worked:
|
Beta Was this translation helpful? Give feedback.
-
I guess this can be closed as it works well with |
Beta Was this translation helpful? Give feedback.
-
I think we can probably keep this open as a feature request, it would be good to have support for this out of the box |
Beta Was this translation helpful? Give feedback.
-
Massive thanks for opening this issue and sharing your solutions. This problem with the aliases not being resolved was driving me crazy. Just to pitch in, I used a combination of two packages to resolve the aliases in
I am at peace now. Thanks. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Link to reproduction
#2748
To Reproduce
Using the Payload template-blank repo, configure your alias paths like this:
Describe the Bug
When I start payload with yarn dev I see errors like this
Module not found: Error: Can't resolve 'Blocks/CallToAction'.
Payload Version
1.9.0
Beta Was this translation helpful? Give feedback.
All reactions