2017-04-06 18 views
0

我試圖將國際化添加到我的Angular 2項目中,並且遵循intructions in the docs無法提取ng-xi18n ENOENT:沒有這樣的文件或目錄

我使用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/。但我不知道如何解決它。

我懷疑的OUTDIR參數tsconfig.json

{ 
    "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是給我了以下問題:

[email protected] invalid 
UNMET PEER DEPENDENCY @angular/[email protected] 
UNMET PEER DEPENDENCY @angular/[email protected] 
+0

其中角CLI版本是你嗎? ng-xi18n是angular-cli的一部分。 –

+0

angular-cli在3.10.10版 – Niel

+0

沒有3.10.10 ...最新版本是1.0.0 –

回答

1

嘗試用ng xi18n

我創建了一個新的角度,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
+0

看起來像是這樣做的......沒有錯誤信息,我有翻譯文件'/ src/messages.xlf'。 '。/ node_modules/.bin/ng-xi18n'和'ng xi18n'之間有什麼區別?我沒有在文檔中看到它。 – Niel

+0

我相信它使用相同的東西,不知道你。如果您嘗試使用「ng --help」或「ng xi18n --help」來查看所有可用的標誌。 –

相關問題