Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tsconfig.json not detecting properly while interop with rust #361

Open
thequantumquirk opened this issue Dec 23, 2022 · 0 comments
Open
Labels
bug Something isn't working

Comments

@thequantumquirk
Copy link

🐛 Bug Report

While interoping Rust with .tsx the tsconfig.json is not picked up properly and throws this error when ran cargo run:

Exception in load_from_file /home/tamizh/Metacall_React-Actix_Example/target/debug/App.js:6
    return (<h1> Hello {text}</h1>);
            ^

SyntaxError: Unexpected token '<'

Expected Behavior

The app directory looks something like this:
image

The app/App.tsx looks like this:

import React from 'react';
import { renderToString } from 'react-dom/server';

export function hello(text: string): string {
	return renderToString(<h1>Hello {text}</h1>);
}

Its called in Rust like this:

    let scripts = ["app/App.tsx".to_string()];

    if let Err(e) = metacall::load_from_file("ts", &scripts) {
        println!("{}", e);
        panic!();
    }

When cargo run was ran it should properly parse the tsx and provide the desired result

Current Behavior

Instead when cargo run is ran it throws the above mentioned error and panics like this:

Exception in load_from_file /home/tamizh/Metacall_React-Actix_Example/target/debug/App.js:6
    return (<h1> Hello {text}</h1>);
            ^

SyntaxError: Unexpected token '<'
    at Object.compileFunction (node:vm:360:18)
    at wrapSafe (node:internal/modules/cjs/loader:1088:15)
    at Module._compile (node:internal/modules/cjs/loader:1123:27)
    at Object.writeFile (/usr/local/lib/bootstrap.ts:181:15)
    at Object.writeFile (/usr/local/lib/node_modules/typescript/lib/typescript.js:17502:14)
    at printSourceFileOrBundle (/usr/local/lib/node_modules/typescript/lib/typescript.js:100995:16)
    at emitJsFileOrBundle (/usr/local/lib/node_modules/typescript/lib/typescript.js:100873:13)
    at emitSourceFileOrBundle (/usr/local/lib/node_modules/typescript/lib/typescript.js:100796:13)
    at forEachEmittedFile (/usr/local/lib/node_modules/typescript/lib/typescript.js:100517:34)
    at Object.emitFiles (/usr/local/lib/node_modules/typescript/lib/typescript.js:100776:9)
MetaCall failed to load script from file
thread 'main' panicked at 'explicit panic', src/main.rs:37:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

However when I place the contents in app/ in the root directory like this:
image
It works as expected

Possible Solution

The metacall module should be able to detect the tsconfig.json file inside the specifed paths too

@thequantumquirk thequantumquirk added the bug Something isn't working label Dec 23, 2022
thequantumquirk added a commit to thequantumquirk/Metacall_React-Actix-Example that referenced this issue Jan 2, 2023
The previous implementation didn't work due to an issue with metacall
Learn more: metacall/core#361
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant