angular2 i18n 无法读取未定义的属性“创建”
Posted
技术标签:
【中文标题】angular2 i18n 无法读取未定义的属性“创建”【英文标题】:angular2 i18n Cannot read property 'create' of undefined 【发布时间】:2017-05-12 18:23:38 【问题描述】:我正在使用 angular2。 我使用this project 启动应用程序。
实现多语言支持遵循this documentation
步骤: 1)执行命令
npm install @angular/compiler-cli @angular/platform-server --save
输出:
+-- 未满足的对等依赖 rxjs@5.0.0-rc.5 `-- 未满足对等的依赖 tslint@4.0.2
npm WARN 可选跳过可选依赖:fsevents@^1.0.0 (node_modules\chokidar\node_modules\fsevents):npm WARN notsup 跳过可选依赖:不支持的平台 fsevents@1.0.15: 想要 "os":"darwin","arch" :"any"(当前: "os":"win32","arch":"x64") npm WARN @angular/core@2.1.1 需要一个 rxjs@5.0.0-beta.12 的对等点,但没有安装。 npm 警告 @angular/forms@2.2.4 需要 @angular/core@2.2.4 的对等体,但没有 已安装。 npm WARN @angular/forms@2.2.4 需要一个 @angular/common@2.2.4 但没有安装。 npm 警告 @angular/http@2.1.1 需要 rxjs@5.0.0-beta.12 的对等点,但没有一个是 安装。 npm WARN @angular/router@3.1.1 需要一个对等点 rxjs@5.0.0-beta.12 但没有安装。 npm 警告 codelyzer@1.0.0-beta.4 需要 tslint@^3.9.0 的对等点,但没有一个是 安装。 npm WARN codelyzer@1.0.0-beta.4 需要一个peer @angular/compiler@~2.2.0 但没有安装。 npm 警告 codelyzer@1.0.0-beta.4 需要 @angular/core@~2.2.0 的对等点,但 没有安装。 npm WARN tslint-loader@2.1.5 需要一个对等点 tslint@^3.0.0 但没有安装。 npm 警告 @angular/compiler-cli@2.4.1 需要 @angular/compiler@2.4.1 的同级 但没有安装。 npm WARN @angular/compiler-cli@2.4.1 需要 @angular/core@2.4.1 的对等体,但没有安装。
2) 执行命令“./node_modules/.bin/ng-xi18n” 它给了我以下错误
C:\Projects\temp\PathTrak3\PathTrak>"./node_modules/.bin/ng-xi18n" TypeError:无法读取未定义的属性“创建” 在 Function.Extractor.create (C:\Projects\temp\PathTrak3\PathTrak\node_modules\@angular\compiler-cli\src\extractor .js:69:45) 在提取处 (C:\Projects\temp\PathTrak3\PathTrak\node_modules\@angular\compiler-cli\src\extract_i18n.js:7:34) 在 Object.main (C:\Projects\temp\PathTrak3\PathTrak\node_modules\@angular\tsc-wrapped\src\main.js:47:16) 在对象。 (C:\Projects\temp\PathTrak3\PathTrak\node_modules\@angular\compiler-cli\src\extract_i18n.js: 14:9) 在 Module._compile (module.js:570:32) 在 Object.Module._extensions..js (module.js:579:10) 在 Module.load (module.js:487:32) 在 tryModuleLoad (module.js:446:12) 在 Function.Module._load (module.js:438:3) 在 Module.runMain (module.js:604:10) 处提取失败
由于这个错误,我无法实现 i18n。 请在 package.json 文件中找到以下依赖项
"dependencies":
"@angular/common": "2.1.1",
"@angular/compiler": "2.1.1",
"@angular/compiler-cli": "^2.4.1",
"@angular/core": "2.1.1",
"@angular/forms": "^2.1.1",
"@angular/http": "2.1.1",
"@angular/platform-browser": "2.1.1",
"@angular/platform-browser-dynamic": "2.1.1",
"@angular/platform-server": "^2.1.1",
"@angular/router": "3.1.1",
"@angularclass/conventions-loader": "^1.0.2",
"@angularclass/hmr": "~1.2.0",
"@angularclass/hmr-loader": "~3.0.2",
"angular2-highcharts": "^0.4.0",
"assets-webpack-plugin": "^3.4.0",
"core-js": "^2.4.1",
"http-server": "^0.9.0",
"ie-shim": "^0.1.0",
"rxjs": "^5.0.0-rc.1",
"zone.js": "~0.6.17"
是否是 package.json 文件中的版本问题? 请帮忙
谢谢, 萨达尔纳尔
----------------------------------修改------ --------------
我删除了 node_modules 文件夹并尝试如下更新 package.json ,UNMET dpendancy 问题已解决,但在运行时出现错误 错误
C:\Projects\temp\PathTrak12\PathTrak>npm start
> angular2-webpack-starter@5.1.1 start C:\Projects\temp\PathTrak12\PathTrak
> npm run server:dev
> angular2-webpack-starter@5.1.1 server:dev C:\Projects\temp\PathTrak12\PathTrak
> webpack-dev-server --config config/webpack.dev.js --progress --profile --watch --content-base src/
keywords if/then/else require v5 option
C:\Projects\temp\PathTrak12\PathTrak\config\webpack.common.js:178
new ForkCheckerPlugin(),
^
TypeError: ForkCheckerPlugin is not a constructor
at module.exports (C:\Projects\temp\PathTrak12\PathTrak\config\webpack.common.js:178:7)
at Object.<anonymous> (C:\Projects\temp\PathTrak12\PathTrak\config\webpack.dev.js:23:31)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at requireConfig (C:\Projects\temp\PathTrak12\PathTrak\node_modules\webpack\bin\convert-argv.js:98:18)
at C:\Projects\temp\PathTrak12\PathTrak\node_modules\webpack\bin\convert-argv.js:111:17
at Array.forEach (native)
at module.exports (C:\Projects\temp\PathTrak12\PathTrak\node_modules\webpack\bin\convert-argv.js:109:15)
at Object.<anonymous> (C:\Projects\temp\PathTrak12\PathTrak\node_modules\webpack-dev-server\bin\webpack-dev-server.js:190:48)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:149:9)
npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "server:de
v"
npm ERR! node v6.9.1
npm ERR! npm v3.10.8
npm ERR! code ELIFECYCLE
npm ERR! angular2-webpack-starter@5.1.1 server:dev: `webpack-dev-server --config config/webpack.dev.js --progress --profile --watch
--content-base src/`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the angular2-webpack-starter@5.1.1 server:dev script 'webpack-dev-server --config config/webpack.dev.js --progres
s --profile --watch --content-base src/'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the angular2-webpack-starter package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! webpack-dev-server --config config/webpack.dev.js --progress --profile --watch --content-base src/
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs angular2-webpack-starter
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls angular2-webpack-starter
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! C:\Projects\temp\PathTrak12\PathTrak\npm-debug.log
npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start"
npm ERR! node v6.9.1
npm ERR! npm v3.10.8
npm ERR! code ELIFECYCLE
npm ERR! angular2-webpack-starter@5.1.1 start: `npm run server:dev`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the angular2-webpack-starter@5.1.1 start script 'npm run server:dev'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the angular2-webpack-starter package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! npm run server:dev
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs angular2-webpack-starter
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls angular2-webpack-starter
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! C:\Projects\temp\PathTrak12\PathTrak\npm-debug.log
package.json 文件
"dependencies":
"@angular/common": "~2.4.1",
"@angular/compiler": "~2.4.1",
"@angular/compiler-cli": "~2.4.1",
"@angular/core": "~2.4.1",
"@angular/forms": "~2.4.1",
"@angular/http": "~2.4.1",
"@angular/platform-browser": "~2.4.1",
"@angular/platform-browser-dynamic": "~2.4.1",
"@angular/platform-server": "~2.4.1",
"@angular/router": "~3.4.1",
"@angularclass/conventions-loader": "^1.0.2",
"@angularclass/hmr": "~1.2.2",
"@angularclass/hmr-loader": "~3.0.2",
"angular2-highcharts": "^0.4.0",
"assets-webpack-plugin": "^3.4.0",
"core-js": "^2.4.1",
"http-server": "^0.9.0",
"ie-shim": "^0.1.0",
"rxjs": "~5.0.2",
"zone.js": "~0.7.4"
,
"devDependencies":
"@types/hammerjs": "^2.0.33",
"@types/jasmine": "^2.2.34",
"@types/node": "^6.0.38",
"@types/protractor": "^1.5.20",
"@types/selenium-webdriver": "2.53.38",
"@types/source-map": "^0.5.0",
"@types/uglify-js": "^2.0.27",
"@types/webpack": "^2.0.0",
"angular2-template-loader": "^0.6.0",
"awesome-typescript-loader": "~3.0.0-beta.17",
"codelyzer": "~2.0.0-beta.4",
"copy-webpack-plugin": "^4.0.0",
"css-loader": "^0.26.0",
"exports-loader": "^0.6.3",
"expose-loader": "^0.7.1",
"file-loader": "^0.9.0",
"gh-pages": "^0.12.0",
"html-webpack-plugin": "^2.21.0",
"imports-loader": "^0.7.0",
"istanbul-instrumenter-loader": "1.2.0",
"json-loader": "^0.5.4",
"karma": "^1.2.0",
"karma-chrome-launcher": "^2.0.0",
"karma-coverage": "^1.1.1",
"karma-jasmine": "^1.0.2",
"karma-mocha-reporter": "^2.0.0",
"karma-remap-coverage": "^0.1.4",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "1.8.1",
"node-sass": "^4.1.1",
"parse5": "^2.2.1",
"protractor": "^4.0.10",
"raw-loader": "0.5.1",
"rimraf": "~2.5.4",
"sass-loader": "^4.1.1",
"script-ext-html-webpack-plugin": "1.3.2",
"source-map-loader": "^0.1.5",
"string-replace-loader": "1.0.5",
"style-loader": "^0.13.1",
"to-string-loader": "^1.1.4",
"ts-helpers": "1.1.2",
"ts-node": "^2.0.0",
"tslint": "^4.0.0-dev.0",
"tslint-loader": "^3.3.0",
"typedoc": "^0.5.3",
"typescript": "2.0.10",
"url-loader": "^0.5.7",
"webpack": "^2.1.0-beta",
"webpack-dev-middleware": "^1.6.1",
"webpack-dev-server": "2.2.0-rc.0",
"webpack-md5-hash": "^0.0.5",
"webpack-merge": "~2.0.0"
【问题讨论】:
也许这可以帮助你:***.com/questions/41259979/… 【参考方案1】:我猜这只是您的角度版本不匹配。对于每个 @angular
软件包,您应该坚持使用相同的版本(除了路由器,它将比 1 个主要版本高直到 angular 4 发布)。
用你的...
npm install @angular/compiler-cli @angular/platform-server --save
...看来您在 2.4.1 时至少有 @angular/compiler-cli
,并且可能在 2.4.1 时有 @angular/platform-server
。由于您已将 其他 @angular
软件包设置为 2.1.1 的固定版本,因此会有一些冲突。
注意:文档将始终假定您使用的是最新(稳定)的 Angular 版本。
那么如何解决它...
1。安装旧包
您可以通过将@angular/compiler-cli
和@angular/platform-server
添加到您的package.json
中的固定2.1.1 来安装旧软件包(不要忘记在此处删除插入符号(^)) .然后删除您的 node_modules
文件夹并再次运行 npm install
。
2。 ...或更新其他软件包
另一种选择是将您的 other@angular
软件包也更新到最新的 2.4.1 版本。在这里,您必须将您的 2.1.1 替换为 package.json
中的 2.4.1(路由器除外,即 3.4.1强>)。
然后删除您的node_modules
文件夹并再次运行npm install
。
在这里,您可能会遇到一些其他问题,具体取决于您的应用...您可能需要先检查Changelog。
仅供参考:当您在项目中安装新的@angular
软件包时,请始终坚持使用您现在使用的版本。要在您的情况下安装特定版本(请注意@2.1.1
):
npm install @angular/compiler-cli@2.1.1 @angular/platform-server@2.1.1 --save
...或全部更新到新版本 ;-)
【讨论】:
能否请您检查有问题的修改部分。我已经删除了 node_modules 文件夹并更新了 package.json 并完成了 npm 安装。在运行时它给了我错误。请帮忙。 关于您更新的错误,问题似乎是您在 3.x.x 使用awesome-typescript-loader
包,看起来他们删除了其中的 ForkCheckerPlugin
(请参阅 this 票证)。所以你必须修改你的 webpack 配置。我的印象是你可能会更好地为你的项目使用Angular-CLI。看看吧,它可能会让你头疼:-)以上是关于angular2 i18n 无法读取未定义的属性“创建”的主要内容,如果未能解决你的问题,请参考以下文章
在angular2应用程序中运行ng serve时出现错误'无法读取未定义的属性'长度''
无法读取 nativescript angular2 中未定义的属性全局数组
NgZone/Angular2/Ionic2 TypeError:无法读取未定义的属性“运行”