Closed nightsailer closed 1 year ago
Based on the fact that it's looking for "eact-three" instead of "react-three" it looks like this might be related to issue #766
I don't run into this issue myself in practice as I usually use the require()
function for my JavaScript imports, For example:
React = require('react')
useState = React.useState
useRef = React.useRef
From there, React
, useState
, and useRef
can be imported into other modules and used just as plain Python objects/functions.
The only "tricky" part of doing it this way is determining how the JavaScript functions were exported in the JS library in order to get the require()
syntax correct. Sometime you have to use
require('libName')[default]
or
require('libName')[NameOfFunction]
to get it to map properly. The biggest benefit to doing it this way IMO is that it keeps almost all of your code in the Python world, and there is less JavaScript to deal with.
@JennaSys Thanks!
Yes, I known the tricky of require. I just read doc example and try to figure why my stuff not works.
I search and browse a lot of opened/closed issues about transcrypt, but not found any related.
It's confirmed the compiler bug, I should not import js local module anymore.
Hi,
I read docs section:
6.8. Example: Using the Parcel.js bundler to package a set of modules written in diverse programming languages.
It shows that transcrypt support python module import javascript module directly.
I write a demo to test following docs, but failed.
test example layout:
`-- src/app.py:
import demo
DemoEditor = demo.DemoEditor
def App(): return DemoEditor()
--- src/demo.js
import React, { useRef, useState } from "react"; import { Canvas, useFrame } from "@react-three/fiber";
export function DemoEditor(props) { return
I compile with following cmd:
$> python -m transcrypt --nomin --map --verbose ./src/app.py
then error occurred, messages:
` (flarekit) ➜ demo git:(develop) ✗ python -m transcrypt --nomin --map --verbose ./src/app.py
Transcrypt (TM) Python to JavaScript Small Sane Subset Transpiler Version 3.9.0 Copyright (C) Geatec Engineering. License: Apache 2.0
Parsing module: /opt/data/mambaforge/envs/flarekit/lib/python3.9/site-packages/transcrypt/modules/org/transcrypt/runtime.py Generating code for module: /Users/night/working/demo/src/target/org.transcrypt.runtime.js Saving source map in: /Users/night/working/demo/src/target/org.transcrypt.runtime.map Saving target code in: /Users/night/working/demo/src/target/org.transcrypt.runtime.js Parsing module: ./src/app.py Generating code for module: /Users/night/working/demo/src/target/app.js Saving target code in: /Users/night/working/demo/src/target/demo.js Parsing module: /opt/data/mambaforge/envs/flarekit/lib/python3.9/site-packages/transcrypt/modules//init.py Generating code for module: /Users/night/working/demo/src/target/.js Saving source map in: /Users/night/working/demo/src/target/.map Saving target code in: /Users/night/working/demo/src/target/.js
Error while compiling (offending file last): File './src/app.py', line 1, at import of: File 'demo', line 1, namely:
Aborted `
I've install required npm packages.
It's weird, if I remove
import { Canvas, useFrame } from "@react-three/fiber";
It works!
So, I reproduced to add/remove some libs, finally, only three/reactjs will pass , other libs can't find.
Is it any limit? How can I import 3rd libs from these local js module?