oracle / graaljs

A high-performance, ECMAScript compliant, and embeddable JavaScript runtime for Java
https://www.graalvm.org/javascript/
Universal Permissive License v1.0
1.8k stars 190 forks source link

No language for id regex found, Supported languages are: [js] #815

Closed ljy1058318852 closed 6 months ago

ljy1058318852 commented 6 months ago

environment

JAVA11.0

MVN project

MacOS

Pom.xml configuration:


<dependency>

<groupId>org. galalvm. sdk</groupId>

<artifactId>grain sdk</artifactId>

<version>22.3.5</version>

</dependency>

<dependency>

<groupId>org. galalvm. js</groupId>

<artifactId>js</artifactId>

<version>22.3.5</version>

</dependency>

<dependency>

<groupId>org. galalvm. js</groupId>

<artifactId>js scriptengine</artifactId>

<version>22.3.5</version>

</dependency>

<dependency>

<groupId>org. galalvm. truffle</groupId>

Truffle API

<version>22.3.5</version>

</dependency>

Call code:


Context context=Context. create();

String jsCode="...";

Context. eval ("js", jsCode);

Successfully run a section of JavaScript in idea;

After packaging into fatjar, the operation failed with an error:


SyntaxError: No language for id regex found Supported languages are: [js]

No language for id regex found Supported languages are: [js]

At org. galalvm. polyglot Context. eval (Context. java: 425)
ljy1058318852 commented 6 months ago

After investigation, I found that this JavaScript code is not supported and points to a new RegExp:

function hex_normalize(data) {
    return data.toLowerCase().replace(new RegExp('[^\\da-f]', 'gi'), '');
}

error:

at com.oracle.truffle.js.runtime.JavaScriptRealmBoundaryRootNode.execute(JavaScriptRealmBoundaryRootNode.java:88)
    at <js> hex_normalize(Unnamed:40:1304-1332)
ljy1058318852 commented 6 months ago

Found the reason, due to package conflicts and packaging overwriting.

By modifying the packaging plugin, it will allow components with duplicate names to coexist. This is my mvn pom.xml:

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.5.2</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <shadedArtifactAttached>false</shadedArtifactAttached>
                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>com.potato.potatotool.ToStart</mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>