我正在尝试将国际化添加到我的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
答案 0 :(得分: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"
然后清理一切:
node_modules
文件夹。@angular/cli
全局依赖npm uninstall -g @angular/cli
npm install -g @angular/cli
npm install