rafi16jan / micropython-wasm Goto Github PK
View Code? Open in Web Editor NEWA WebAssembly module built from the official MicroPython port
Home Page: https://www.npmjs.com/package/micropython
License: MIT License
A WebAssembly module built from the official MicroPython port
Home Page: https://www.npmjs.com/package/micropython
License: MIT License
I tried pulling in this npm package and compiling it with webpack but I get the following errors:
ERROR in ./node_modules/micropython/index.js
Module not found: Error: Can't resolve 'fs' in './micropython_example/node_modules/micropython'
@ ./node_modules/micropython/index.js 21:9-22
@ ./assets/js/app.js
@ ./assets/js/index.js
ERROR in ./node_modules/micropython/lib/micropython.js
Module not found: Error: Can't resolve 'fs' in './micropython_example/node_modules/micropython/lib'
@ ./node_modules/micropython/lib/micropython.js 39:15-28 80:13-26 179:28-41 3005:23-36
@ ./node_modules/micropython/index.js
@ ./assets/js/app.js
@ ./assets/js/index.js
This appears to be because webpack is not detecting that it can never go down the "node-only" path and still trying to require fs
. If I add typeof __webpack_require__ !== 'function'
on every branch that requires fs
, everything works. But I don't know enough about webpack to be confident such changes are a good idea and/or they wouldn't break it for someone else.
You can see my webpack version and config and a working example at https://github.com/tessereth/micropython_wasm_example.
I am trying to compile on master
@ 21bf511f93dd94a5ac05626b5a94c70d7492d427
(Save my work at micropython-wasm), but is not compiling:
$ time make
Use make V=1 or set BUILD_VERBOSE in your environment to increase build verbosity.
mkdir -p build/genhdr
GEN build/genhdr/mpversion.h
GEN build/genhdr/moduledefs.h
GEN build/genhdr/qstr.i.last
GEN build/genhdr/qstr.split
GEN build/genhdr/qstrdefs.collected.h
QSTR updated
GEN build/genhdr/qstrdefs.generated.h
mkdir -p build/extmod
mkdir -p build/lib/embed
mkdir -p build/lib/mp-readline
mkdir -p build/lib/utils
mkdir -p build/py
CC ../../py/mpstate.c
(...)
CC ../../lib/mp-readline/readline.c
CC main.c
CC mphalport.c
CC modutime.c
LINK build/firmware.js
emcc:WARNING: ignoring unsupported linker flag: `-Map=build/micropython.js.map`
emcc:WARNING: ignoring unsupported linker flag: `--cref`
emcc:WARNING: ignoring unsupported linker flag: `--gc-sections`
error: undefined symbol: mp_module_js
warning: To disable errors for undefined symbols use `-s ERROR_ON_UNDEFINED_SYMBOLS=0`
Error: Aborting compilation due to previous errors
shared:ERROR: '/Users/alanjds/src/git/emsdk/node/8.9.1_64bit/bin/node /Users/alanjds/src/git/emsdk/fastcomp/emscripten/src/compiler.js /tmp/tmpvPCwWN.txt /Users/alanjds/src/git/micropython/ports/javascript/library.js /Users/alanjds/src/git/emsdk/fastcomp/emscripten/src/library_pthread_stub.js' failed (1)
make: *** [build/micropython.js] Error 1
real 0m50.846s
user 0m31.518s
sys 0m18.148s
Am I doing something wrong?
Trying to use micropython.js following the npmjs readmem somehow an internal node_modules/micropython/index.js:113:49
could not be imported.
// index.js
import mp_js from 'micropython';
/*
(async () => {
await mp_js;
mp_js.init(64 * 1024);
mp_js.do_str("print('hello world')\n");
})();
*/
๐จ /Users/alanjds/src/git/parcel-plugin-micropython/node_modules/micropython/index.js:113:49: Unexpected token, expected ";" (113:49)
111 | return await methods.do_str(pyjs);
112 | }
> 113 | methods.register_module = async (module, code) {
| ^
114 | if (!pyjs_initiated) return pyjs += '\n' + await methods.do_str(code, module, false);
115 | return await methods.do_str(code, module, true);
116 | }
May be possible to this package to have some specification issue on packages.json
?
Looks like some babel translation is not being applied? But I could not find it by myself. Am I looking at the wrong place/path?
Context:
$ node --version
v9.11.2
$ cat package.json
{
"name": "helloworld",
"version": "1.0.0",
"description": "An absolute bare-bones web app.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "parcel serve web/index.html"
},
"author": "",
"license": "ISC",
"dependencies": {
"eslint": "^6.0.1",
"parcel-plugin-micropython": "file:../.."
},
"devDependencies": {
"@babel/core": "^7.2.2"
}
}
Ran the following code but didn't see any repl response...
Am I doing something wrong?
Running mp_js.do_str does execute print statements though....
const mp_js = require('micropython') \\ I waited till promises fulfilled for each
mp_js.init(64*1024)
mp_js.init_repl()
let b = new TextEncoder().encode('print(\'hello world\')')
for(let i = 0; i < b.length; i++){
mp_js.process_char(b[ i ])
}
mp_js.process_char("\r".charCodeAt(0))
mp_js.process_char("\n".charCodeAt(0))
I don't know how much this is to do with your code or Emscripten, but if your python code raises an exception, the do_str
promise never resolves. Eg:
import mp_js from 'micropython'
async () => {
await mp_js.init(64 * 1024)
const stdout = await mp_js.do_str(`invalid syntax`)
console.log(stdout) // <-- this never logs and no exception is raised
}();
This makes it very difficult to debug what could be going wrong. It would be great if python exceptions were accessible in some way, even if just logged to console, and the promise rejected.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.