toonvanstrijp / nestjs-i18n

The i18n module for nestjs.
https://nestjs-i18n.com
Other
642 stars 106 forks source link

Initializes i18n module before app is built #481

Closed JuanPedroPontVerges closed 1 year ago

JuanPedroPontVerges commented 1 year ago

So im using this package on my backend and im struggling with this:

On applications start, when it starts to log all initializations, it throws me this error:

[Error: ENOENT: no such file or directory, stat '/usr/src/app/dist/i18n/'] { errno: -2, code: 'ENOENT', syscall: 'stat', path: '/usr/src/app/dist/i18n/' }

To debug, i sh into my container and went to '/usr/src/app/dist/i18n/' to see if i18n folder is copied, and it indeed is.

image

So when i make any changes to my code, and save, servers restarts and it doesnt throw me the error anymore. This makes me suppose that i18n module tries to initialize before the folder is copied into dist.

This is how it´s initializated in my app.module.ts

I18nModule.forRoot({ fallbackLanguage: 'es', loaderOptions: { path: path.join(__dirname, '/i18n/'), }, typesOutputPath: path.join(__dirname, '../src/generated/i18n.generated.ts'), viewEngine: 'hbs', resolvers: [ new QueryResolver(['lang', 'l']) ], }),

and my nest-cli.json

{ "collection": "@nestjs/schematics", "sourceRoot": "src", "compilerOptions": { "plugins": ["@nestjs/swagger"], "assets": [ { "include": "email-templates/*", "outDir": "dist" }, { "include": "i18n/**/*", "outDir": "dist" } ] } }

I´ve followed every step in the quick start guide and it kind of works, because once you start the app, make a change in the code and save it, when it restarts it reads the i18n module, but on application start, it seems that is not finding it

JuanPedroPontVerges commented 1 year ago

Fixed the problem by deleteing outDir in nest-cli.json, and adding watchAssets: true