Can't work with `monorepo` mode
wxs77577 opened this issue · 6 comments
It does not work after I move to monorepo mode:
https://docs.nestjs.com/cli/monorepo
Version: typescript 3.6.4
Time: 96ms
Hash: 636664306cf42961350d
Version: webpack 4.41.0
Time: 104ms
Built at: 2019-10-18 23:57:22
Entrypoint main = apps/admin/main.js
[Nest] 46523 - 2019-10-18 23:57:22 [NestFactory] Starting Nest application...
[Nest] 46523 - 2019-10-18 23:57:22 [InstanceLoader] DbModule dependencies initialized +14ms
[Nest] 46523 - 2019-10-18 23:57:22 [InstanceLoader] AppModule dependencies initialized +1ms
/Users/johnny/projects/test/topfullstack-test/server/libs/db/src/db.config.ts:1
export default {
^^^^^^
SyntaxError: Unexpected token export
at Module._compile (internal/modules/cjs/loader.js:720:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:643:32)
at Function.Module._load (internal/modules/cjs/loader.js:556:12)
at Module.require (internal/modules/cjs/loader.js:683:19)
at require (internal/modules/cjs/helpers.js:16:16)
at /Users/johnny/projects/test/topfullstack-test/server/node_modules/nestjs-config/dist/module/config.service.js:224:28
at Array.reduce (<anonymous>)
at Function.configGraph (/Users/johnny/projects/test/topfullstack-test/server/node_modules/nestjs-config/dist/module/config.service.js:223:28)
at /Users/johnny/projects/test/topfullstack-test/server/node_modules/nestjs-config/dist/module/config.service.js:198:42
It's not about nestjs-config for sure.
Your entry point is apps/admin/main.js
and the problem is here ...libs/db/src/db.config.ts
So are you sure you compile libs/db/src
folder? I pretty sure you don't
@zMotivat0r Thanks for your reply, but how could I fix it in monorepo mode?
/config/app.ts
export default {
name: 'APP',
secret: process.env.SECRET
}
It throws an error:
C:\work\code\nest-test\config\app.ts:1
export default {
^^^^^^
SyntaxError: Unexpected token export
...
If I move app.ts
to app.js
with module.exports
it works.
module.exports = {
name: 'APP',
secret: process.env.SECRET
}
How could I use typescript
in my configuration files?
What's your config glob? Looks like it's using ts files in prod.
ConfigModule.load(path.resolve('config', '**/!(*.d).{ts,js}'))
Your path includes every file from where the process is run from Which is not what you want to do because this will include any file ending with .ts
or .js
. It's best to use a relative dir using ___dirname
to only pick the files relative to where your main file is being called. I would use this instead ConfigModule.load(path.resolve(__dirname, 'config', '**/!(*.d).{ts,js}'))