无法提取ng-xi18n ENOENT:没有这样的文件或目录

时间:2017-04-06 20:33:37

标签: node.js angular internationalization angular-cli

我正在尝试将国际化添加到我的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

1 个答案:

答案 0 :(得分:1)

尝试使用ng xi18n

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

ng new i18n-test
cd i18n-test
ng xi18n

工作得很好。

如果这不起作用,请确保package.jsondev-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