【问题标题】:Module parse failed: Parenthesized pattern You may need an appropriate loader to handle this file type模块解析失败:带括号的模式您可能需要适当的加载程序来处理此文件类型
【发布时间】:2017-06-20 04:36:20
【问题描述】:

我使用这些命令创建了一个全新的 angular 2 应用程序:

ng init
ng server

我得到这个错误输出:

chunk    {1} styles.bundle.js, styles.bundle.map (styles) 9.96 kB {3} [initial] [rendered]
chunk    {2} vendor.bundle.js, vendor.bundle.map (vendor) 2.65 MB [initial] [rendered]
chunk    {3} inline.bundle.js, inline.bundle.map (inline) 0 bytes [entry] [rendered]
ERROR in ./~/@angular/core/src/util/decorators.js
Module parse failed: /Users/nikolaschou/Dev/coziv/sandbox01/blockhowapp/temp/node_modules/@angular/core/src/util/decorators.js Parenthesized pattern (156:12)
You may need an appropriate loader to handle this file type.
|if (clsDef.hasOwnProperty('extends')) {
|  if (typeof clsDef.extends === 'function') {

谁能解释我为什么会收到这个错误?我看到很多类似的错误报告,但不完全是这种变化。

更多详情

我可以说 ng serve 在同一台机器上的另一个 angular-2 应用程序文件夹中运行良好,我已经比较了这两个文件夹,但没有发现任何可以解释这种行为的明显差异。

我使用带有最新 iOS 的 Mac,这是 ng --version 的输出:

angular-cli: 1.0.0-beta.26
node: 6.6.0
os: darwin x64
@angular/common: 2.4.5
@angular/compiler: 2.4.5
@angular/core: 2.4.5
@angular/forms: 2.4.5
@angular/http: 2.4.5
@angular/platform-browser: 2.4.5
@angular/platform-browser-dynamic: 2.4.5
@angular/router: 3.4.5
@angular/compiler-cli: 2.4.5

【问题讨论】:

  • 你使用的是哪个版本的 webpack?我们在 webpack/backbone 设置中遇到了类似的问题。
  • 我们也刚刚开始看到这一点。使用 webpack 2.2.0。我猜有人的传递依赖升级并且正在破坏事情..
  • 最新的@angular/cli beta.29,webpack 2.2.0 - 同样的东西
  • 我想可能是npmjs.com/package/acorn ?最近从 4.0.4 更新到 4.0.5 是的。在此处查看此问题:github.com/ternjs/acorn/issues/502

标签: angular webpack


【解决方案1】:

导致此失败的依赖项现已更新。如果你卸载 webpack 并重新安装 webpack,它会将 acorn 更新到 4.0.7 版本。这应该可以解决您的问题。

https://github.com/ternjs/acorn/issues/502

或者直接运行

npm i acorn@4.0.8 来自项目目录(感谢@nodarii)

【讨论】:

  • 只需从项目目录运行npm i acorn@4.0.7
  • 我应该补充一点,我刚刚运行了 npm i acorn@4.0.7 并在此 ng serve 再次运行后立即运行。
  • 他们是 acorn@4.0.7 的一些挥之不去的问题 - 他们刚刚发布了 4.0.8 修复了所有问题。我已经更新了我的答案。
猜你喜欢
  • 2018-02-27
  • 2019-10-11
  • 1970-01-01
  • 2017-03-25
  • 2020-07-30
  • 2017-10-22
  • 1970-01-01
  • 2019-01-28
  • 2018-07-12
相关资源
最近更新 更多