当前位置: 首页 > 知识库问答 >
问题:

angular2 i18n无法读取未定义的属性“create”

马庆
2023-03-14

我正在使用Angular2.br>我使用这个项目开始应用程序。

要实现多语言支持,请遵循以下文档

步骤:1)执行命令

npm install @angular/compiler-cli @angular/platform-server --save

输出:

+--unmeted PEER DEPENDENCY rxjs@5.0.0-rc.5-unmeted PEER DEPENDENCY tslint@4.0.2

npm WARN可选跳过可选依赖项:fsevents@1.0.0(node_moduleschokidarnode_modulesfsevents:npm WARN notsup跳过可选依赖项:Unsupported platform for fsevents@1.0.15:wanted os:darwin.arch“:any}(当前:os:win32,arch:x64})npm WARN@angular/core@2.1.1需要rxjs@5.0.0-beta.12的对等项,但未安装任何对等项。npm WARN@angular/forms@2.2.4需要@angular/core@2.2.4的对等体,但未安装任何对等体。npm WARN@angular/forms@2.2.4需要@angular/common@2.2.4的对等项,但未安装任何对等项。npm WARN@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 WARN codelyzer@1.0.0-beta.4需要tslint@3.9.0的对等项,但未安装任何对等项。npm WARN codelyzer@1.0.0-beta.4需要@angular/compiler@2.2.0的对等体,但未安装任何对等体。npm WARN codelyzer@1.0.0-beta.4需要@angular/core@2.2.0的对等体,但未安装任何对等体。npm WARN tslint-loader@2.1.5需要tslint@3.0.0的对等项,但未安装任何对等项。npm WARN@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:projecttTempPathtrak3pathtrak>./node_modules/.bin/ng-xi18n“TypeError:无法读取object.main(c:projecttTempPathtrak3pathtraknode_modules@angularcompiler-clisrcextract_i18n.js:7:34)中function.extractor.create(c:projecttTempPathtrak3pathtraknode_modules@angularcompiler-clisrcextractor.js:69:45)中未定义的属性(c:projectstempPathtrak3Pathtraknode_modules@angularcompiler-clisrcExtract_i18n.js:14:9)在module._compile(module.js:570:32)在object.module._extensions..js(module.js:579:10)在module.load(module.js:487:32)在module.load(module.js:446:12)在function.module._load(module.js:438:3)在module.runmain

由于这个错误,我无法实现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文件中的版本问题吗?好心的帮助

谢谢,Sardar Nale

-----修改----------------------------------------

我删除了node_modules文件夹并尝试如下更新package.json,未满足的挂起问题已解决,但在运行时给出了错误

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"
  }

共有1个答案

万喜
2023-03-14

我猜这只是你的角度版本不匹配。对于每个 包,您应该坚持使用相同的版本(除了路由器,在angular 4发布之前,它将高出一个主要版本)。

和你的。。。。

npm install @angular/compiler-cli @angular/platform-server --save

。。。看来您在2.4.1的位置至少有 ,可能在2.4.1的位置有 。由于您已经将其他 包设置为2.1.1的固定版本,因此会出现一些冲突。

注意:文档总是假设你是最新的(稳定的)角度版本。

那么如何修复它。。。

您只需添加 &即可安装旧的软件包; 修复了 json ode=""> 中的2.1.1(不要忘记删除这里的插入符号(^))。然后删除 文件夹并再次运行

另一种选择是将您的othercode@angular/code>包也更新到最新的2.4.1版本。在这里,您必须用 中的2.4.1替换您的2.1.1(除了路由器是3.4.1)。然后删除 文件夹并再次运行

在这里,你可能会遇到一些其他问题,这取决于你的应用程序。。。您可能需要先检查更改日志。

供参考:当您在项目中安装一个新的 包时,请始终坚持使用当前使用的版本。在您的情况下,要安装特定的版本,应该是(请注意

npm install @angular/compiler-cli@2.1.1 @angular/platform-server@2.1.1 --save

。。。或全部更新到新版本-)

 类似资料:
  • 我正在测试发送电子邮件与流星js和nodemailer插件: 流星添加捷运:流星NodeEmailer 当页面加载时,我在导航器的控制台上看到错误:无法读取未定义的属性“创建运输”。 那么问题是什么呢? 代码如下: /////////////////////////////////////////// ///////////////

  • 为什么我得到这个错误不能读取未定义的触摸属性? 为什么它不能读取,但它可以读取 当我们使用

  • 问题内容: 我正在制作非常简单的react应用。但是,当我尝试通过onChange事件调用父(实际上是祖父母)组件的方法时,我一直在获取。 这是触发事件的组件/表单(因此,在绑定的父组件上调用方法…是的,因为我通过道具将其从父组件传递下来,所以在方法上使用了.bound(this)。) 这是我如何通过大多数父(祖父母)组件中的props传递该方法的方法。 这是我作为父项(方法所有者和方法调用程序之

  • 我知道这方面还有很多类似的问题,但没有一个答案是有效的。在我的例子中,我有下面的代码,我正在尝试按分数降序排列记录数组。 最后一个函数是什么给我的问题.如果用户运行以下: var web=[{url:“www.southanpton.ac.uk”,内容:“南安普敦大学提供学位课程和世界一流的研究测试。”,{url:“www.xyz.ac.uk”,内容:“另一种大学考试”},{url:“www”,内

  • 我一直试图让firebase与react一起工作,但出现了此错误 未经处理的拒绝(TypeError):无法读取未定义的fetch D:/Peti/Programming/node/coursewebpage/src/components/coursePage.js:12 9 | const db=firebase.firestore()10 | const myAuthLevel=(fireba

  • 这是我的猫鼬模式: 这是使用Express的Node.js服务器。它具有路由,如果触发该路由,它将使用请求中传递的信息更新用户的购物车。正文: 我打印到终端userCart,正如您在代码中看到的,它返回给我的是: 当服务器执行时,它返回以下错误: 如果我已经在Mongoose中定义了的结构,为什么不定义它?

  • 请注意,我在react ProductScreen.js中呈现动态数据时有问题 注意,...数据在product.js中呈现得很好,但相同的数据在productscreen.js中不会呈现,因为productscreen.js链接是通过“id”呈现的。 谢谢app.js 导入“./homescreen.css”;从'../Components/Product'导入产品从'React'导入{useE

  • 我正在使用webpack,浏览器中出现以下错误: 编译时没有错误或警告。 validator.js的第15行如下所示: