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

Window error while testing artoolkit5-js with nodejs #1

Closed
kalwalt opened this issue Feb 18, 2020 · 9 comments
Closed

Window error while testing artoolkit5-js with nodejs #1

kalwalt opened this issue Feb 18, 2020 · 9 comments

Comments

@kalwalt
Copy link

kalwalt commented Feb 18, 2020

Hi @andypotato i tested the project with a simple nodejs project:

My package.json:

{
  "name": "test-artoolkit5-js",
  "version": "1.0.0",
  "description": "test",
  "main": "index.js",
  "scripts": {
    "test": "node index.js"
  },
  "keywords": [
    "jsartoolkit5"
  ],
  "author": "kalwalt",
  "license": "ISC",
  "dependencies": {
    "artoolkit5-js": "0.0.1"
  }
}

My index.js simply is:

const ARToolkit = require('artoolkit5-js');

in the output i get:

npm run test 
> test-artoolkit5-js@1.0.0 test /home/walter/kalwalt-github/test/test-artoolkit5-js
> node index.js

/home/walter/kalwalt-github/test/test-artoolkit5-js/node_modules/artoolkit5-js/dist/ARToolkit.js:1
!function(A,I){"object"==typeof exports&&"object"==typeof module?module.exports=I():"function"==typeof define&&define.amd?define([],I):"object"==typeof exports?exports.ARToolkit=I():A.ARToolkit=I()}(window,(function(){return function(A){var I={};function g(B){if(I[B])return I[B].exports;var C=I[B]={i:B,l:!1,exports:{}};return A[B].call(C.exports,C,C.exports,g),C.l=!0,C.exports}return g.m=A,g.c=I,g.d=function(A,I,B){g.o(A,I)||Object.defineProperty(A,I,{enumerable:!0,get:B})},g.r=function(A){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(A,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(A,"__esModule",{value:!0})},g.t=function(A,I){if(1&I&&(A=g(A)),8&I)return A;if(4&I&&"object"==typeof A&&A&&A.__esModule)return A;var B=Object.create(null);if(g.r(B),Object.defineProperty(B,"default",{enumerable:!0,value:A}),2&I&&"string"!=typeof A)for(var C in A)g.d(B,C,function(I){return A[I]}.b

ReferenceError: window is not defined
    at Object.<anonymous> (/home/walter/kalwalt-github/test/test-artoolkit5-js/node_modules/artoolkit5-js/dist/ARToolkit.js:1:200)
    at Module._compile (internal/modules/cjs/loader.js:1151:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1171:10)
    at Module.load (internal/modules/cjs/loader.js:1000:32)
    at Function.Module._load (internal/modules/cjs/loader.js:899:14)
    at Module.require (internal/modules/cjs/loader.js:1040:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (/home/walter/kalwalt-github/test/test-artoolkit5-js/index.js:1:19)
    at Module._compile (internal/modules/cjs/loader.js:1151:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1171:10)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! test-artoolkit5-js@1.0.0 test: `node index.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the test-artoolkit5-js@1.0.0 test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

This becasue window is not supported by nodejs, i tried to fix this in my experimental branch https://github.com/kalwalt/jsartoolkit5/blob/a13cad4cd2731ddd001e6f5a5a755a73554355e9/js/artoolkit.api.js#L1-L11

I will do other tests! 🙂

@andypotato
Copy link
Owner

@kalwalt the code you're referencing is not included in my build. The issue seems to result from a polyfill Babel uses to transpile import.meta.url

Will check it

@kalwalt
Copy link
Author

kalwalt commented Feb 19, 2020

Looking in your code i saw that --pre-js is not used in your project

@kalwalt the code you're referencing is not included in my build. The issue seems to result from a polyfill Babel uses to transpile import.meta.url

Will check it

ok thank you!

@andypotato
Copy link
Owner

I created a new build which fixes the "window reference" issue with Node.js. Root cause of the issue was Emscripten injecting an ES6 import.meta directive which I tried to work around - but obviously with limited success.

There is a new flag USE_ES6_IMPORT_META=0 in Emscripten now which will use a more compatible legacy fallback function for importing. And since my build WASM is a single-file build there is no need for any imports anyway.

Please have a try!

@kalwalt
Copy link
Author

kalwalt commented Feb 19, 2020

Yes i will try, which version of emscripten are you using?

@andypotato
Copy link
Owner

@kalwalt

% emcc --version
emcc (Emscripten gcc/clang-like replacement) 1.39.8

I will push another version tomorrow which implements the first methods like loadCamera(), addMarker() etc.

@kalwalt
Copy link
Author

kalwalt commented Feb 19, 2020

That's Awesome! Emscripten fastcomp or upstream?

@andypotato
Copy link
Owner

Starting from 1.39.6 emscripten defaults to upstream. I'm using 1.39.8 to compile to WASM so it's using upstream now.

@kalwalt
Copy link
Author

kalwalt commented Feb 19, 2020

Thank you for the info, i will test also the build under linux (Ubuntu 18.04) . I can confirm that this issue is solved, just tested it. 😄

@kalwalt kalwalt closed this as completed Feb 19, 2020
@andypotato
Copy link
Owner

Wonderful!

I've also just committed a fresh build - nothing spectacular, but it should give you a pretty good idea which direction I'm going with the code. Check out this file for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants