vaadin / flow

Vaadin Flow is a Java framework binding Vaadin web components to Java. This is part of Vaadin 10+.
Apache License 2.0
618 stars 167 forks source link

ImportExtractor fails when using module that contains ".from" in name #19157

Open muhammetaltindal opened 6 months ago

muhammetaltindal commented 6 months ago

Description of the bug

The build-frontend goal fails in class com.vaadin.flow.server.frontend.ImportExtractor when some of the used JS code contains a module import with .from in the name. The reason is because the maven plugin code cannot distinguish between the real from token and any "from" char sequence in an imported module name, e.g. for import 'core-js/modules/es6.array.from';

The maven stacktrace looks like this:

org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.vaadin:vaadin-maven-plugin:23.5.0:build-frontend (default) on project centerdevice-web-client: Could not execute build-frontend goal
...
Caused by: org.apache.maven.plugin.MojoFailureException: Could not execute build-frontend goal
    at com.vaadin.flow.plugin.maven.BuildFrontendMojo.execute (BuildFrontendMojo.java:109)
...
Caused by: com.vaadin.flow.server.ExecutionFailedException: Error occured during goal execution: begin 1, end 0, length 1Please run Maven with the -e switch (or Gradle with the --stacktrace switch), to learn the full stack trace.
    at com.vaadin.flow.plugin.base.BuildFrontendUtil.runNodeUpdater (BuildFrontendUtil.java:341)
    at com.vaadin.flow.plugin.maven.BuildFrontendMojo.execute (BuildFrontendMojo.java:107)
...
Caused by: java.lang.StringIndexOutOfBoundsException: begin 1, end 0, length 1
    at java.lang.String.checkBoundsBeginEnd (String.java:4602)
    at java.lang.String.substring (String.java:2705)
    at com.vaadin.flow.server.frontend.ImportExtractor.strip (ImportExtractor.java:94)
    at com.vaadin.flow.server.frontend.ImportExtractor.getImportedPaths (ImportExtractor.java:71)
    at com.vaadin.flow.server.frontend.AbstractUpdateImports.visitImportsRecursively (AbstractUpdateImports.java:602)
    at com.vaadin.flow.server.frontend.AbstractUpdateImports.handleImports (AbstractUpdateImports.java:650)
    at com.vaadin.flow.server.frontend.AbstractUpdateImports.getUniqueEs6ImportPaths (AbstractUpdateImports.java:375)
    at com.vaadin.flow.server.frontend.AbstractUpdateImports.getModuleLines (AbstractUpdateImports.java:413)
    at com.vaadin.flow.server.frontend.AbstractUpdateImports.collectModules (AbstractUpdateImports.java:324)
    at com.vaadin.flow.server.frontend.AbstractUpdateImports.run (AbstractUpdateImports.java:128)
    at com.vaadin.flow.server.frontend.TaskUpdateImports.execute (TaskUpdateImports.java:389)
    at com.vaadin.flow.server.frontend.NodeTasks.execute (NodeTasks.java:334)
    at com.vaadin.flow.plugin.base.BuildFrontendUtil.runNodeUpdater (BuildFrontendUtil.java:335)
    at com.vaadin.flow.plugin.maven.BuildFrontendMojo.execute (BuildFrontendMojo.java:107)
...

Expected behavior

The expected behavior is that the build-frontend succeeds.

Minimal reproducible example

Add any JS file to the project that contains the following import:

import 'core-js/modules/es6.array.from';

Versions

muhammetaltindal commented 6 months ago

I have avoided/deleted those kind of imports, now the builds work just fine.