I am creating a ubuntu:20.04 docker container and installing python 3.9 and node 16.x along with npm. I am then running a js library with a javascript to python bridge. The library is mineflyer and I am using it to create a discord.py bot. Running the files outside of a docker continer works perfectly fine(windows 10) but when I run the file inside one, it give me a error.
ERROR:
Traceback (most recent call last):
File "/code/bot.py", line 7, in <module>
from mcbot import cheekline
File "/code/mcbot.py", line 2, in <module>
[JSE] /usr/local/lib/python3.9/dist-packages/javascript/js/bridge.js:14
[JSE] const debug = process.env.DEBUG?.includes('jspybridge') ? console.debug : () => { }
[JSE] ^
[JSE] SyntaxError: Unexpected token .
[JSE] at Module._compile (internal/modules/cjs/loader.js:723:23)
[JSE] at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
[JSE] at Module.load (internal/modules/cjs/loader.js:653:32)
[JSE] at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
[JSE] at Function.Module._load (internal/modules/cjs/loader.js:585:3)
[JSE] at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
[JSE] at startup (internal/bootstrap/node.js:283:19)
[JSE] at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
** The Node process has crashed. Please restart the runtime to use JS APIs. **
Timed out get 0 needsNodePatches None
from javascript import require, On, Once, AsyncTask, once, off
File "/usr/local/lib/python3.9/dist-packages/javascript/__init__.py", line 20, in <module>
init()
File "/usr/local/lib/python3.9/dist-packages/javascript/__init__.py", line 16, in init
if config.global_jsi.needsNodePatches():
File "/usr/local/lib/python3.9/dist-packages/javascript/proxy.py", line 225, in __getattr__
methodType, val = self._exe.getProp(self._pffid, attr)
File "/usr/local/lib/python3.9/dist-packages/javascript/proxy.py", line 145, in getProp
resp = self.ipc("get", ffid, method)
File "/usr/local/lib/python3.9/dist-packages/javascript/proxy.py", line 38, in ipc
raise Exception(f"Timed out accessing '{attr}'")
Exception: Timed out accessing 'needsNodePatches'
I have this script in my setup.py file:
status = subprocess.check_output(["node", "/setupLocalAPI/app.js"])
print(status)
That should call the node server and output it's output (which would be the fact the server has started),
yet whenever I call it I get the error of:
internal/modules/cjs/loader.js:979
throw err;
^
Error: Cannot find module 'c:\setupLocalAPI\app.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:976:15)
at Function.Module._load (internal/modules/cjs/loader.js:859:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
Traceback (most recent call last):
File "c:\Users\Nathan\Dropbox\Projects\projectname\projectnamesourcecode\startup.py", line 20, in <module>
setup.init()
File "c:\Users\Nathan\Dropbox\Projects\projectname\projectnamesourcecode\setup\setup.py", line 31, in init
status = subprocess.check_output(["node", "/setupLocalAPI/app.js"])
File "C:\Users\Nathan\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 411, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
File "C:\Users\Nathan\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 512, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['node', '/setupLocalAPI/app.js']' returned non-zero exit status 1.
My project layout is as follows:
setup
setup.py
__init__.py
setupLocalAPI
app.js
Use a relative path ./setupLocalAPI/app.js
JavaScript code:
node
const Web3 = require('web3')
const web3 = new Web3('network-link')
console.log(web3.eth.accounts.create())
Now I saved this file in the desktop: file.js
Command prompt code:
path/path/path/path
cd Desktop
path/path/path/path/Desktop
node file
This outputs:
ReferenceError: node is not defined
at Object.<anonymous> (C:\Users\HP\Desktop\file.js:1:1)
[90m at Module._compile (internal/modules/cjs/loader.js:956:30)[39m
[90m at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)[39m
[90m at Module.load (internal/modules/cjs/loader.js:812:32)[39m
[90m at Function.Module._load (internal/modules/cjs/loader.js:724:14)[39m
[90m at Function.Module.runMain (internal/modules/cjs/loader.js:1025:10)[39m
[90m at internal/main/run_main_module.js:17:11[39m
You need to remove node in first line of your code, after refactoring it will be as
const Web3 = require('web3')
const web3 = new Web3('network-link')
console.log(web3.eth.accounts.create())
Because you neither declared node as a variable nor as a function. So when file gets run then node is undefined.
I am trying this sample code for WebGL and the problem is that my build getting failed. Here is my code.
jslib
margeInto(LibraryManager.library,{
GameObjectHasClicked : function (str){
window.alert(Pointer_stringify(str));
},
Hello: function (){
window.alert(Pointer_stringify(str));
},
});
And UnityC# script
using System.Runtime.InteropServices;
using UnityEngine;
public class SendInfoToBrowserJS : MonoBehaviour {
[DllImport("__Internal")]
private static extern void GameObjectHasClicked(string pos);
[DllImport("__Internal")]
private static extern void Hello();
private void OnMouseDown()
{
string currentPos = this.transform.position.ToString();
Debug.Log("cube clicked "+ currentPos);
//#if UNITY_WEBGL
Hello();
GameObjectHasClicked(currentPos);
//#endif
}
}
As you can see that I am calling two simple methods (GameObjectHasClicked,Hello) of jslib from C#, but
First, it giving me error whenever I click the gameobject in editor mode
EntryPointNotFoundException: Hello
SendInfoToBrowserJS.OnMouseDown () (at Assets/Scripts/SendInfoToBrowserJS.cs:29)
UnityEngine.SendMouseEvents:DoSendMouseEvents(Int32)
Second, the build is failing with success (but no build) message as well. Actually there are three messsages:
The first Error Message:
Failed running "C:/Program
Files/Unity2018.2.10/Editor/Data/PlaybackEngines/WebGLSupport\BuildTools\Emscripten_Win\python\2.7.5.3_64bit\python.exe"
"C:/Program
Files/Unity2018.2.10/Editor/Data/PlaybackEngines/WebGLSupport\BuildTools\Emscripten\emcc"
#"D:\#TLL_Projects\WebGLAndBroswerJSInteraction\Assets\..\Temp\emcc_arguments.resp"
stdout: stderr:WARNING:root:--separate-asm works best when compiling
to HTML. Otherwise, you must yourself load the '.asm.js' file that is
emitted separately, and must do so before loading the main '.js' file.
[-Wseparate-asm] error: failure to execute js library
"D:\#TLL_Projects\WebGLAndBroswerJSInteraction\Assets\Plugins\ExternalJSMethod.jslib":
ReferenceError: margeInto is not defined,,ReferenceError: margeInto is
not defined at eval (eval at load (eval at globalEval (C:\ProgramFiles\Unity2018.2.10\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\src\compiler.js:105:8)),
<anonymous>:1:1) at Object.load (eval at globalEval (C:\ProgramFiles\Unity2018.2.10\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\src\compiler.js:105:8),
<anonymous>:178:9) at JSify (eval at globalEval (C:\ProgramFiles\Unity2018.2.10\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\src\compiler.js:105:8),
<anonymous>:84:20) at
D:\#TLL_Projects\WebGLAndBroswerJSInteraction\Assets\Plugins\ExternalJSMethod.jslib
(C:\ProgramFiles\Unity2018.2.10\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\src\compiler.js:208:3)
at Module._compile (module.js:570:32) at
Object.Module._extensions..js (module.js:579:10) at Module.load
(module.js:487:32) at tryModuleLoad (module.js:446:12) at
Function.Module._load (module.js:438:3) at Module.runMain
(module.js:604:10)preprocessed source (you can run a js engine on this
to get a clearer error message
sometimes):=============margeInto(LibraryManager.library,{ GameObjectHasClicked
: function (str){ window.alert(Pointer_stringify(str)); }, Hello:
function
(){ window.alert(Pointer_stringify(str)); },});=============Internal
compiler error in src/compiler.js! Please raise a bug report at
https://github.com/kripken/emscripten/issues/ with a log of the build
and the input files used to run. Exception message: "ReferenceError:
margeInto is not defined" | ReferenceError: margeInto is not defined
at eval (eval at load (eval at globalEval (C:\ProgramFiles\Unity2018.2.10\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\src\compiler.js:105:8)),
<anonymous>:1:1) at Object.load (eval at globalEval (C:\ProgramFiles\Unity2018.2.10\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\src\compiler.js:105:8),
<anonymous>:178:9) at JSify (eval at globalEval (C:\ProgramFiles\Unity2018.2.10\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\src\compiler.js:105:8),
<anonymous>:84:20) at Object.<anonymous> (C:\ProgramFiles\Unity2018.2.10\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\src\compiler.js:208:3)
at Module._compile (module.js:570:32) at
Object.Module._extensions..js (module.js:579:10) at Module.load
(module.js:487:32) at tryModuleLoad (module.js:446:12) at
Function.Module._load (module.js:438:3) at Module.runMain
(module.js:604:10)Traceback (most recent call last): File
"C:/Program
Files/Unity2018.2.10/Editor/Data/PlaybackEngines/WebGLSupport\BuildTools\Emscripten\emcc",
line 10, in <module>
python_selector.run(__file__, profile=True) File "C:\Program Files\Unity2018.2.10\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\tools\python_selector.py",
line 43, in run
sys.exit(run_by_import(filename, main) if on_allowed_version() else run_by_subprocess(filename)) File "C:\ProgramFiles\Unity2018.2.10\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\tools\python_selector.py",
line 13, in run_by_import
return getattr(importlib.import_module(os.path.basename(filename)), main)()
File "C:\ProgramFiles\Unity2018.2.10\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\emcc.py",
line 1611, in run
final = shared.Building.emscripten(final, append_ext=False, extra_args=extra_args) File "C:\ProgramFiles\Unity2018.2.10\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\tools\shared.py",
line 2009, in emscripten
call_emscripten(cmdline) File "C:\Program Files\Unity2018.2.10\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\emscripten.py",
line 2340, in _main
temp_files.run_and_clean(lambda: main( File "C:\Program Files\Unity2018.2.10\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\tools\tempfiles.py",
line 93, in run_and_clean
return func() File "C:\Program Files\Unity2018.2.10\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\emscripten.py",
line 2345, in <lambda>
DEBUG=DEBUG, File "C:\Program Files\Unity2018.2.10\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\emscripten.py",
line 2251, in main
temp_files=temp_files, DEBUG=DEBUG) File "C:\Program Files\Unity2018.2.10\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\emscripten.py",
line 99, in emscript
glue, forwarded_data = compiler_glue(metadata, settings, libraries, compiler_engine, temp_files, DEBUG) File "C:\ProgramFiles\Unity2018.2.10\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\emscripten.py",
line 226, in compiler_glue
glue, forwarded_data = compile_settings(compiler_engine, settings, libraries, temp_files) File "C:\ProgramFiles\Unity2018.2.10\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\emscripten.py",
line 532, in compile_settings
cwd=path_from_root('src'), error_limit=300) File "C:\Program Files\Unity2018.2.10\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\tools\jsrun.py",
line 132, in run_js
raise Exception('Expected the command ' + str(command) + ' to finish with return code ' + str(assert_returncode) + ', but it
returned with code ' + str(proc.returncode) + ' instead! Output: ' +
str(ret)[:error_limit]) Exception: Expected the command ['C:/Program
Files/Unity2018.2.10/Editor/Data\\Tools\\nodejs\\node.exe',
'--stack_size=8192', '--max-old-space-size=4096', 'C:\ProgramFiles\\Unity2018.2.10\\Editor\\Data\\PlaybackEngines\\WebGLSupport\\BuildTools\\Emscripten\\src\\compiler.js',
'C:\\Users\\User\\AppData\\Local\\Temp\\tmppocs11.txt', 'C:\ProgramFiles\\Unity2018.2.10\\Editor\\Data\\PlaybackEngines\\WebGLSupport\\BuildTools\\lib\\Audio.js',
'C:\ProgramFiles\\Unity2018.2.10\\Editor\\Data\\PlaybackEngines\\WebGLSupport\\BuildTools\\lib\\Cursor.js',
'C:\ProgramFiles\\Unity2018.2.10\\Editor\\Data\\PlaybackEngines\\WebGLSupport\\BuildTools\\lib\\Eval.js',
'C:\ProgramFiles\\Unity2018.2.10\\Editor\\Data\\PlaybackEngines\\WebGLSupport\\BuildTools\\lib\\FileSystem.js',
'C:\ProgramFiles\\Unity2018.2.10\\Editor\\Data\\PlaybackEngines\\WebGLSupport\\BuildTools\\lib\\Logging.js',
'C:\ProgramFiles\\Unity2018.2.10\\Editor\\Data\\PlaybackEngines\\WebGLSupport\\BuildTools\\lib\\Profiler.js',
'C:\ProgramFiles\\Unity2018.2.10\\Editor\\Data\\PlaybackEngines\\WebGLSupport\\BuildTools\\lib\\SystemInfo.js',
'C:\ProgramFiles\\Unity2018.2.10\\Editor\\Data\\PlaybackEngines\\WebGLSupport\\BuildTools\\lib\\UnetWebSocket.js',
'C:\ProgramFiles\\Unity2018.2.10\\Editor\\Data\\PlaybackEngines\\WebGLSupport\\BuildTools\\lib\\Video.js',
'C:\ProgramFiles\\Unity2018.2.10\\Editor\\Data\\PlaybackEngines\\WebGLSupport\\BuildTools\\lib\\WebCam.js',
'C:\ProgramFiles\\Unity2018.2.10\\Editor\\Data\\PlaybackEngines\\WebGLSupport\\BuildTools\\lib\\WebGL.js',
'C:\ProgramFiles\\Unity2018.2.10\\Editor\\Data\\PlaybackEngines\\WebGLSupport\\BuildTools\\lib\\WebRequest.js',
'D:\\#TLL_Projects\\WebGLAndBroswerJSInteraction\\Assets\\Plugins\\ExternalJSMethod.jslib',
'C:\ProgramFiles\\Unity2018.2.10\\Editor\\Data\\PlaybackEngines\\WebGLSupport\\BuildTools\\Emscripten\\src\\library_pthread_stub.js']
to finish with return code 0, but it returned with code 1 instead!
Output: // The Module object: Our interface to the outside world. We
import // and export values on it. There are various ways Module can
be used: // 1. Not defined. We create it here // 2. A function
parameter, function(Module) { ..generated code.. } // 3. pre-run
appended it, var Module = {}; ..generated
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
The second Error Message
Exception: Failed building WebGL Player.
UnityEditor.WebGL.ProgramUtils.StartProgramChecked
(System.Diagnostics.ProcessStartInfo p) (at
/Users/builduser/buildslave/unity/build/PlatformDependent/WebGL/Extensions/Unity.WebGL.extensions/ProgramUtils.cs:48)
UnityEditor.WebGL.WebGlBuildPostprocessor.EmscriptenLink
(BuildPostProcessArgs args, Boolean wasmBuild, System.String
sourceFiles, System.String sourceFilesHash) (at
/Users/builduser/buildslave/unity/build/PlatformDependent/WebGL/Extensions/Unity.WebGL.extensions/BuildPostprocessor.cs:425)
UnityEditor.WebGL.WebGlBuildPostprocessor.LinkBuild
(BuildPostProcessArgs args) (at
/Users/builduser/buildslave/unity/build/PlatformDependent/WebGL/Extensions/Unity.WebGL.extensions/BuildPostprocessor.cs:474)
UnityEditor.WebGL.WebGlBuildPostprocessor.PostProcess
(BuildPostProcessArgs args) (at
/Users/builduser/buildslave/unity/build/PlatformDependent/WebGL/Extensions/Unity.WebGL.extensions/BuildPostprocessor.cs:937)
UnityEditor.Modules.DefaultBuildPostprocessor.PostProcess
(BuildPostProcessArgs args, UnityEditor.BuildProperties&
outProperties) (at
C:/buildslave/unity/build/Editor/Mono/Modules/DefaultBuildPostprocessor.cs:27)
UnityEditor.PostprocessBuildPlayer.Postprocess (BuildTargetGroup
targetGroup, BuildTarget target, System.String installPath,
System.String companyName, System.String productName, Int32 width,
Int32 height, BuildOptions options, UnityEditor.RuntimeClassRegistry
usedClassRegistry, UnityEditor.Build.Reporting.BuildReport report) (at
C:/buildslave/unity/build/Editor/Mono/BuildPipeline/PostprocessBuildPlayer.cs:287)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
And the last success message
Build completed with a result of 'Succeeded'
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
I closely inspect my First error
Failed running "C:/Program
Files/Unity2018.2.10/Editor/Data/PlaybackEngines/WebGLSupport\BuildTools\Emscripten_Win\python\2.7.5.3_64bit\python.exe"
"C:/Program
Files/Unity2018.2.10/Editor/Data/PlaybackEngines/WebGLSupport\BuildTools\Emscripten\emcc"
#"D:#TLL_Projects\WebGLAndBroswerJSInteraction\Assets..\Temp\emcc_arguments.resp"
stdout: stderr:WARNING:root:--separate-asm works best when compiling
to HTML. Otherwise, you must yourself load the '.asm.js' file that is
emitted separately, and must do so before loading the main '.js' file.
[-Wseparate-asm] error: failure to execute js library
"D:#TLL_Projects\WebGLAndBroswerJSInteraction\Assets\Plugins\ExternalJSMethod.jslib":
ReferenceError: margeInto is not defined,,ReferenceError: margeInto is
not defined at eval (eval at load (eval at globalEval (C:\Program . .. . .**so on**
and found that the problem is here
ReferenceError: **margeInto is not defined**,,ReferenceError: margeInto is
not defined at eval (eval at load
Actually it is mergeInto not margeInto, by replacing the syntax error i am able to build successfully.
I have downloaded jsfeat from here, and unzipped the downloaded file.
Inside the directory, I wrote the following:
require("./build/jsfeat.js");
var matrix = new jsfeat.matrix_t(2,2, jsfeat.U8_t | jsfeat.C1_t);
matrix.data[1] = 4;
console.log(matrix.data[1]);
I ran the program as follows:
$ node matrix.js
But, got the following error:
/Users/abc/Desktop/JavaScript/inspirit-jsfeat-59cc928/matrix.js:2
var matrix = new jsfeat.matrix_t(2,2, jsfeat.U8_t | jsfeat.C1_t);
^
ReferenceError: jsfeat is not defined
at Object.<anonymous> (/Users/abc/Desktop/JavaScript/inspirit-jsfeat-59cc928/matrix.js:2:19)
at Module._compile (module.js:425:26)
at Object.Module._extensions..js (module.js:432:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Function.Module.runMain (module.js:457:10)
at startup (node.js:136:18)
at node.js:972:3
Why is that? How can I solve the issue?
Thanks.
You need to assign the imported module to a variable:
var jsfeat = require("./build/jsfeat.js");
If you prefer you could install the module with NPM to save downloading it manually:
$ npm install jsfeat
The module will be saved to ./node_modules/jsfeat. You can then require it with var jsfeat = require('jsfeat').