ng-xi18n脚本失败,因为它正在检查scss/sass文件

Tho*_*iel 7 angular

开始使用angular2s rc6 i18n,我想运行ng-xi18n脚本来提取相应的i18n属性以便进一步处理.

但是脚本失败并显示消息

/project ??? npm run extract                                                                                

> test.com@0.0.1 extract C:\project
> ng-xi18n

Error: Compilation failed. Resource file not found: C:/project/src/styles/colors
    at Object.resourceLoader.get (C:\project\node_modules\@angular\compiler-cli\src\extract_i18n.js:127:27)
    at DirectiveNormalizer._fetch (C:\project\node_modules\@angular\compiler\bundles\compiler.umd.js:13450:45)
    at C:\project\node_modules\@angular\compiler\bundles\compiler.umd.js:13552:55
    at Array.map (native)
    at DirectiveNormalizer._loadMissingExternalStylesheets (C:\project\node_modules\@angular\compiler\bundles\compiler.umd.js:13552:16)
    at C:\project\node_modules\@angular\compiler\bundles\compiler.umd.js:13555:28
    at process._tickCallback (node.js:382:9)
    at Function.Module.runMain (module.js:433:11)
    at startup (node.js:141:18)
    at node.js:977:3
TypeError: Cannot read property 'write' of undefined
    at C:\project\node_modules\@angular\compiler-cli\src\extract_i18n.js:34:46
    at process._tickCallback (node.js:382:9)
    at Function.Module.runMain (module.js:433:11)
    at startup (node.js:141:18)
    at node.js:977:3
Extraction failed
Run Code Online (Sandbox Code Playgroud)

显然,脚本找不到文件C:/ project/src/styles/colors,这是完全正确的,因为这是一个sass partial,因此被命名为_colors并在styleUrls中使用的组件自己的sass文件中引用:[]

我可以将脚本限制为仅调查特定文件(例如所有*.ts)或为什么要调查我的样式表?

如果调查样式表文件是有效的,那么脚本似乎不知道sass部分语法.

我正在使用webpack来捆绑和处理styleUrls中的sass文件引用:[]在我生成的文件中内联.但这不应该是一个问题,因为ng-xi18n运行在未捆绑的源上.

任何提示都表示赞赏.谢谢.

小智 1

我最近也遇到了同样的问题。为了使ng-xi18n我成为可翻译的消息包,我只是用空字符串替换文件@import '.+?';中的所有内容并按照github上的描述执行。.scss./node_modules/.bin/ng-xi18n -p src/tsconfig.json

您已经问过,为什么它会调查您的样式文件...发生这种情况是因为ng-xi18n分析任何模块的附件,并且此过程需要编译组件并解析组件的样式导入...偶尔,它会将它们解析为无效...