【问题标题】:Vaadin addon javascript not found in webpack在 webpack 中找不到 Vaadin 插件 javascript
【发布时间】:2021-06-22 08:36:05
【问题描述】:

我发现了适用于 Vaadin 14+ 的非常有前途的 VStepper 插件,但不幸的是我无法让它与 Vaadin 20 一起运行。

当使用 VStepper 添加一些代码时,我总是得到一个 java.lang.IllegalStateException。其他人有同样的问题吗?

Tomcat 8 存在问题。该插件与 Springboot 一起使用。 v-stepper.js 已添加到 node_modules/@vaadin/flow-frontend/ 但 NpmTemplateParser 无法找到它。

堆栈跟踪:

java.lang.IllegalStateException: Couldn't find the definition of the element with tag 'v-stepper' in any template file declared using '@JsModule' annotations. Check the availability of the template files in your WAR file or provide alternative implementation of the method getTemplateContent() which should return an element representing the content of the template file
    at com.vaadin.flow.component.polymertemplate.NpmTemplateParser.getTemplateContent(NpmTemplateParser.java:155)
    at com.vaadin.flow.component.polymertemplate.TemplateDataAnalyzer.parseTemplate(TemplateDataAnalyzer.java:217)
    at com.vaadin.flow.component.polymertemplate.TemplateInitializer.<init>(TemplateInitializer.java:100)
    at com.vaadin.flow.component.polymertemplate.PolymerTemplate.<init>(PolymerTemplate.java:94)
    at com.vaadin.flow.component.polymertemplate.PolymerTemplate.<init>(PolymerTemplate.java:109)
    at com.mlottmann.vstepper.VStepper.<init>(VStepper.java:53)

【问题讨论】:

  • 您能否更具体地说明您如何运行导致(和不导致)此错误的事情?我们可以假设“Tomcat 8”是指您部署了应用程序的独立 Tomcat 吗? “使用springboot”是什么意思-就像在运行fatjar或使用某些构建工具任务时使用嵌入式服务器一样?您正在使用生产版本,对吗?
  • 我可以尝试更详细地解释它:“Tomcat 8”是指在我们开发应用程序时使用 IDE 和 maven 构建和非生产模式部署到独立的 tomcat 8 的 Web War 应用程序。 “Springboot”是指在@SpringBootApplication注解类上使用“debug as java application”启动应用程序的jar包。另请参阅下面@Limespace 的答案,因为这是对问题的进一步调查。

标签: webpack vaadin vaadin-flow


【解决方案1】:

编辑:

我在 Windows 上也有同样的 spring-boot 问题。使用原始 vaadin 启动器下载(vaadin 20、java 8、仅流)并添加插件我得到相同的错误消息。

调试显示同样的问题:

AbstractConfiguration.class
default String getFlowResourcesFolder() {
        return Paths.get(getBuildFolder(),
                FrontendUtils.DEFAULT_FLOW_RESOURCES_FOLDER).toString();
    }

在 Windows 上返回 target\flow-frontend,在 Linux 上返回 target/flow-frontend

自从BundleParser

if (name.contains(FLOW_NPM_PACKAGE_NAME) || name.contains(service
                    .getDeploymentConfiguration().getFlowResourcesFolder())) {
                alternativeFileName = alternativeFileName.replaceFirst("\\./",
                        "");
            }

使用String.contains() 检查是否应删除前导“./”在 Windows 中失败但在 Linux 上有效(原因名称为“../target/flow-frontend/v-stepper.js”)


我尝试对此进行调试,发现给定 webpack 生成的 stats.js 和 getFlowResourcesFolder() 返回的 buildfolder 中的文件夹名称不匹配 这是“目标\流动字体” stats.js 中的模块名称是“../target/flow-frontend/v-stepper.js”

,{"id":"../target/flow-frontend/v-stepper.js","name":"../target/flow-frontend/v-stepper.js","source":"import { ....

这发生在 flow-polymer-template-7.0.2.jar -> com.vaadin.flow.component.polymertemplate.BundleParser.getSourceFromObject(..) L:269

 if (name.contains(FLOW_NPM_PACKAGE_NAME) || name.contains(service
                    .getDeploymentConfiguration().getFlowResourcesFolder())) {
                alternativeFileName = alternativeFileName.replaceFirst("\\./",
                        "");
            }

Snip of Debug Variable content

环境为WIN10,Tomcat 8.5.x,Java 8,Vaadin 20.0.3,mvn build,vaadin NONE生产模式,无spring

【讨论】:

  • 更多信息:它自己的插件正在使用 vaadin 20。我刚刚将所有源导入(复制)到一个简单的测试项目中并使用了 VStepper,它就出现了。
【解决方案2】:

不幸的是,该插件还不支持 Vaadin 20。我问了作者,但他现在没有时间研究。

【讨论】:

  • 我很抱歉,但据我了解,该插件非常适合 Vaadin 14+,这也应该包括 Vaadin 20,不是吗?那么为什么无法在 vaadin 插件存储库中过滤插件?此外,它在使用 springboot 时有效,但在部署到 tomcat 8 时无效。这是 Vaadin 插件的已知问题吗?
  • 在发布新的 Vaadin 版本时,没有对第三方插件的自动验证,因此有时它们会在没有注意到的情况下中断,需要专门添加进一步的支持。
  • 好的,我明白了。我不明白为什么它仍然使用 Vaadin 20 与 springboot 一起使用,而不是使用 maven 和 tomcat 8.5.x?!
  • 这需要进一步调查,是的。如果有人在马蒂亚斯有时间深入研究问题之前解决了这个问题,我相信他会欢迎拉取请求或其他修复帮助。存储库位于github.com/mLottmann/VStepper
猜你喜欢
  • 1970-01-01
  • 2017-04-20
  • 2019-08-09
  • 1970-01-01
  • 1970-01-01
  • 2020-04-30
  • 1970-01-01
  • 2020-05-20
  • 1970-01-01
相关资源
最近更新 更多