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

Trouble using pts on node server #132

Closed
stefa168 opened this issue Dec 27, 2020 · 7 comments
Closed

Trouble using pts on node server #132

stefa168 opened this issue Dec 27, 2020 · 7 comments

Comments

@stefa168
Copy link

stefa168 commented Dec 27, 2020

Hi, today I was working on some server-side TypeScript code that uses Group and Pt.
Unfortunately when I try to run my code, I get a ReferenceError saying window is not defined, which is understandable, since node doesn't have such things

Here's a simple example that throws that exception:

import { Group, Pt } from "pts";

let g = new Group();

Is there any way to use pts' classes on a node server, or am I out of luck?
Thanks!

@williamngan
Copy link
Owner

Hi @stefa168 -- I'm not very familiar with node server, but I'm surprised that 'window' is referenced in the example you've given.

I wonder if something like this would work ...

import { Group, Pt, namespace } from "pts"

namespace( this );
let g = new Group();

Do you have a stack trace of your error message? If you have it, can you share it here? I'll try to find the bug.

Thanks!

@stefa168
Copy link
Author

Hi, thanks for the reply!

I tried adding your suggestion, however the error remains.
I'm sorry I didn't include a stacktrace; I totally forgot to include it:

ReferenceError: window is not defined
    at Object.<anonymous> (/sandbox/node_modules/pts/dist/index.js:15:4)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Module._compile (/sandbox/node_modules/source-map-support/source-map-support.js:547:25)
    at Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Object.nodeDevHook [as .js] (/sandbox/node_modules/ts-node-dev/lib/hook.js:63:13)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
[ERROR] 18:23:35 ReferenceError: window is not defined

@williamngan
Copy link
Owner

Looks like it's related to this webpack setting:
https://webpack.js.org/configuration/output/#outputglobalobject

I'll experiment with the build and see if I can fix this -- hopefully in the next 1-2 weeks. Thanks for reporting this issue.

Happy Holidays!

williamngan added a commit that referenced this issue Feb 13, 2021
@williamngan
Copy link
Owner

Hi @stefa168 - This should be fixed v0.10. Please give it a try. We should be able to add support for node-canvas in future, but for now at least the static functions should work.

@stefa168
Copy link
Author

Hi @williamngan, I just tried version 0.10.1 with a project of mine and it works without any issue!
Thanks a lot, both for the fix and for pts!

@dcsan
Copy link

dcsan commented Nov 18, 2023

(two years later :)
wondering if this lib does work with node canvas?

@williamngan
Copy link
Owner

(two years later :) wondering if this lib does work with node canvas?

Basic node-canvas support is available. Take a look at:
https://github.com/williamngan/node-pts-canvas

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

3 participants