【问题标题】:Can't extract ng-xi18n ENOENT: no such file or directory无法提取 ng-xi18n ENOENT:没有这样的文件或目录
【发布时间】:2017-04-06 20:33:36
【问题描述】:

我正在尝试将国际化添加到我的 Angular 2 项目中,并遵循 intructions in the docs

我使用angular-cli 启动了这个项目,而我的tsconfig.json 在/src 中。

运行命令:

./node_modules/.bin/ng-xi18n -p src/tsconfig.json

我收到以下错误:

Error: ENOENT: no such file or directory, open '/home/project/dist/out-tsc/src/app/_models/example.metadata.json'
    at Error (native)
    at Object.fs.openSync (fs.js:641:18)
    at Object.fs.writeFileSync (fs.js:1347:33)
    at MetadataWriterHost.writeMetadata (/home/project/node_modules/@angular/tsc-wrapped/src/compiler_host.js:164:22)
    at MetadataWriterHost.writeFile (/home/project/node_modules/@angular/tsc-wrapped/src/compiler_host.js:143:19)
    at Object.writeFile (/home/project/node_modules/typescript/lib/typescript.js:64240:132)
    at Object.writeFile (/home/project/node_modules/typescript/lib/typescript.js:9020:14)
    at printSourceFileOrBundle (/home/project/node_modules/typescript/lib/typescript.js:61204:16)
    at emitSourceFileOrBundle (/home/project/node_modules/typescript/lib/typescript.js:61155:21)
    at Object.forEachEmittedFile (/home/project/node_modules/typescript/lib/typescript.js:8986:17)
Extraction failed

没错,/home/project/dist/out-tsc/src/app/ 的目录不存在,而是/home/project/dist/out-tsc/app/。但我不知道如何解决它。

我怀疑 tsconfig.json 中的 outDir 参数

{
  "compilerOptions": {
    "baseUrl": "",
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [
      "es2016",
      "dom"
    ],
    "mapRoot": "./",
    "module": "es2015",
    "moduleResolution": "node",
    "outDir": "../dist/out-tsc",
    "sourceMap": true,
    "target": "es5",
    "typeRoots": [
      "../node_modules/@types"
    ]
  },
  "exclude": [
    "app/testing/*",
    "app/**/*.spec.ts",
    "test.ts"
  ]
}

如果它完全相关,@angular/compiler-cli@angular/platform-server 都在 2.4.10 版本,并且 npm 给我以下问题:

typescript@2.2.2  invalid
UNMET PEER DEPENDENCY @angular/compiler@2.4.10
UNMET PEER DEPENDENCY @angular/forms@2.4.10

【问题讨论】:

  • 您使用的是哪个 angular-cli 版本? ng-xi18n 是 angular-cli 的一部分。
  • angular-cli 版本 3.10.10
  • 没有3.10.10...最新的是1.0.0
  • 对不起,我跑了npm --version -g angular-cling version 告诉我我在 1.0.0

标签: node.js angular internationalization angular-cli


【解决方案1】:

试试ng xi18n

我创建了一个新的 angular-cli(版本 1.0.0):

ng new i18n-test
cd i18n-test
ng xi18n

工作得很好。

如果这不起作用,请确保您的 package.json 具有 dev-dependency "@angular/cli": "1.0.0"

然后清理一切:

  1. 删除项目中的node_modules 文件夹。
  2. 删除@angular/cli全局依赖npm uninstall -g @angular/cli
  3. 安装回来npm install -g @angular/cli
  4. 重新安装你的项目依赖npm install

【讨论】:

  • 看起来是这样...没有错误消息,我有翻译文件/src/messages.xlf./node_modules/.bin/ng-xi18nng xi18n 有什么区别?我在文档中没有看到它。
  • 我相信它使用相同的东西,你不确定。如果你尝试ng --helpng xi18n --help 来查看所有可用的标志。
猜你喜欢
  • 1970-01-01
  • 2018-07-03
  • 2014-01-12
  • 1970-01-01
  • 2023-03-31
  • 2013-07-28
  • 2019-02-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多