nestjsnesti18nextmonoreponomachine-nx

ERROR [I18nService] parsing translation error Error: ENOENT: no such file or directory, stat using | monorepo | nx | nestjs


I have a problem about using i18n with Nest.js with mono repo(nx). I tried so much things but I can't solve the problem. Compiler is not export the i18n folder to dist directory. I am sharing some config files. Thanks your help.

apps/api/src/app/app.module.ts`

@Module({
  imports: [
    ConfigModule.forRoot({
      isGlobal: true,
    }),
    I18nModule.forRoot({
      fallbackLanguage: 'tr',
      loaderOptions: {
        path: path.join(__dirname,'/../i18n/'),
        watch: true,
      },
      resolvers: [
        { use: QueryResolver, options: ['lang'] },
        AcceptLanguageResolver,
      ],
    }),
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

in nest-cli.json (main directory and project directory)

 "compilerOptions": {
    "webpack": true,
    "tsConfigPath": "apps/api/tsconfig.app.json",
    "assets": [
      { 
        "include": "i18n/**/*", 
        "watchAssets": true, 
        "outDir": "dist/apps/api" 
      }
    ]
  },

nx.json

[![{
  "$schema": "./node_modules/nx/schemas/nx-schema.json",
  "npmScope": "test",
  "tasksRunnerOptions": {
    "default": {
      "runner": "@nrwl/nx-cloud",
      "options": {
        "cacheableOperations": \[
          "build",
          "lint",
          "test",
          "e2e"
        \],
        "accessToken": "ZWQ3NjU5MzItNTg2My00YjYxLWFkYTAtOWYwZjVlNGQwM2JkfHJlYWQtd3JpdGU="
      }
    }
  },
  "targetDefaults": {
    "build": {
      "dependsOn": \[
        "^build"
      \],
      "inputs": \[
        "production",
        "^production"
      \]
    },
    "test": {
      "inputs": \[
        "default",
        "^production",
        "{workspaceRoot}/jest.preset.js"
      \]
    },
    "lint": {
      "inputs": \[
        "default",
        "{workspaceRoot}/.eslintrc.json",
        "{workspaceRoot}/.eslintignore"
      \]
    }
  },
  "namedInputs": {
    "default": \[
      "{projectRoot}/**/*",
      "sharedGlobals"
    \],
    "production": \[
      "default",
      "!{projectRoot}/**/?(*.)+(spec|test).\[jt\]s?(x)?(.snap)",
      "!{projectRoot}/tsconfig.spec.json",
      "!{projectRoot}/jest.config.\[jt\]s",
      "!{projectRoot}/.eslintrc.json"
    \],
    "sharedGlobals": \[\]
  }
}]

project structure


Solution

  • I resolved as add above code to project.app.json => build.options.assets array

    "options": {
        "target": "node",
        "compiler": "tsc",
        "outputPath": "dist/apps/api",
        "main": "apps/api/src/main.ts",
        "tsConfig": "apps/api/tsconfig.app.json",
        "assets": [
          "apps/api/src/assets",
          {
            "glob": "**/*",
            "input": "apps/api/src/i18n/",
            "output": "src/i18n"
          }
        ],
        "webpackConfig": "apps/api/webpack.config.js"
      },