ERROR [I18nService] 解析翻译错误 Error: ENOENT: no such file or directory, stat using |单一仓库 | nx |嵌套

问题描述 投票:0回答:1

我在将 i18n 与带有 mono repo(nx) 的 nestjs 一起使用时遇到问题。我尝试了很多东西,但我无法解决问题。编译器不会将 i18n 文件夹导出到 dist 目录。我正在共享一些配置文件。谢谢你的帮助。

应用程序/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 {}

在nest-cli.json(主目录和项目目录)

 "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": \[\]
  }
}]

nestjs nest i18next monorepo nomachine-nx
1个回答
0
投票

我解决了将上面的代码添加到 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"
  },
© www.soinside.com 2019 - 2024. All rights reserved.