简体   繁体   English

没有'new'就不能调用类构造函数PolymerElement

[英]Class constructor PolymerElement cannot be invoked without 'new'

昨天我的应用程序工作得很好但是当我现在做polymer serve -o它打开应用程序并在控制台中打印此错误。

Class constructor PolymerElement cannot be invoked without 'new'
  1. Clear the Cached files and images from your browser cache. 从浏览器缓存中清除缓存的文件和图像。
  2. If you loaded custom-elements-es5-adapter.js , remove it. 如果您加载了custom-elements-es5-adapter.js ,请将其删除。
  3. Then use $ polymer serve --compile never . 然后使用$聚合物服务 - 编译从不

According to this post , this issue is cause because $ polymer serve compiles your code to es5 automatically. 根据这篇文章 ,这个问题是因为$ polymer服务器自动将你的代码编译成es5。 The --compile never flag stops $ polymer serve from doing this. --compile never flag会阻止$聚合物 发挥作用

I had a similar Error the other day after moving my Polymer App to v.2. 在将Polymer App移至v.2后的另一天,我遇到了类似的错误。
This helped me: 对我有所帮助:

To work around this, load custom-elements-es5-adapter.js before declaring new Custom Elements. 要解决此问题,请在声明新的自定义元素之前加载custom-elements-es5-adapter.js。

Since most projects need to support a wide range of browsers that don't necessary support ES6, it may make sense to compile your project to ES5. 由于大多数项目需要支持不需要支持ES6的各种浏览器,因此将项目编译为ES5可能是有意义的。 However, ES5-style custom element classes will not work with native Custom Elements because ES5-style classes cannot properly extend ES6 classes, like HTMLElement. 但是,ES5样式的自定义元素类不适用于本机自定义元素,因为ES5样式的类无法正确扩展ES6类,如HTMLElement。

I build my Polymer App as es5-bundled, and serve it to Android App using WebView. 我将我的Polymer App构建为es5-bundled,并使用WebView将其提供给Android App。 This problem often appears. 这个问题经常出现。

In your polymer.json , add custom-elements-es5-adapter to the excludes array to stop it from being compiled to ES5. 在你polymer.json ,添加custom-elements-es5-adapterexcludes阵列被编译到ES5停止。

  "builds": [
    {
      "bundle": {
        "stripComments": true,
        "inlineCss": true,
        "sourcemaps": false,
        "excludes": [
          "bower_components/webcomponentsjs/webcomponents-loader.js",
          "bower_components/webcomponentsjs/custom-elements-es5-adapter.js"
        ]
      },
      "js": {
        "compile": true,
        "minify": true
      },
      "css": {
        "minify": true
      },
      "html": {
        "minify": true
      },
      "addServiceWorker": false

The problem occurs because Custom Elements v1 requires your code to use ES6 syntax. 出现此问题的原因是自定义元素v1要求您的代码使用ES6语法。 So make sure you don't transpile to anything lower, like ES5. 因此,请确保不要像ES5那样转向更低级别的东西。

For anyone running into this using the Parcel bundler like me; 对于像我这样使用Parcel捆绑包的人来说; by default it compiles your code to ES5 or something, even if you're using Typescript and you've set the tsconfig target to ES6. 默认情况下,它会将您的代码编译为ES5或其他内容,即使您正在使用Typescript并且已将tsconfig目标设置为ES6。

The solution is to tell Parcel what browsers you're targeting, so that it knows it doesn't have to transpile to ES5. 解决方案是告诉Parcel您要定位的浏览器,以便它知道它不必转换为ES5。 One way to do it is to add a "browserlist" field in package.json. 一种方法是在package.json中添加“browserlist”字段。

I found out about this through this video . 我通过这个视频发现了这个。 For more info I suggest you go watch that. 有关更多信息,我建议你去看看。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Polymer 3 + webpack + babel 类构造函数PolymerElement 不能在没有'new'的情况下被调用 - Polymer 3 + webpack + babel Class constructor PolymerElement cannot be invoked without 'new' 如果没有“ new”,则不能调用类构造函数BaseService - Class constructor BaseService cannot be invoked without 'new' 没有new就不能调用类构造函数 - Class constructor cannot be invoked without new 没有'new'就不能调用类构造函数 - Class constructor cannot be invoked without 'new' 错误TypeError:如果没有在Ionic 4中使用“ new”,则无法调用类构造函数EventEmitter - ERROR TypeError: Class constructor EventEmitter cannot be invoked without 'new' in Ionic 4 尝试发布NPM时,“没有'new'不能调用类构造函数” - “Class constructor cannot be invoked without 'new'” when trying to NPM publish Uncaught TypeError:类构造函数Hero不能在没有“ new”的情况下调用 - Uncaught TypeError: Class constructor Hero cannot be invoked without 'new' TypeError:如果没有“ new”,则无法调用类构造函数分页 - TypeError: Class constructor Pagination cannot be invoked without 'new' 类型错误:类构造函数 ESLintWebpackPlugin 不能在没有“new”的情况下被调用 - TypeError: Class constructor ESLintWebpackPlugin cannot be invoked without 'new' 类型错误:类构造函数 Wia 不能在没有“new”的情况下被调用 - TypeError: Class constructor Wia cannot be invoked without 'new'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM