nodejs / node

Node.js JavaScript runtime ✨🐢🚀✨
https://nodejs.org
Other
107.78k stars 29.68k forks source link

Unable to utilize GSAP JS functions using NODEJS, referenced code from: https://greensock.com/docs/v3/GSAP; Bard states an internal bug in NodeJS that needs to be addressed. #49399

Closed ghost closed 1 year ago

ghost commented 1 year ago

Version

node -v v20.5.1

Platform

Microsoft Windows NT 10.0.22621.0 x64

Subsystem

No response

What steps will reproduce the bug?

running this code using nodejs on my PowerShell 7 terminal: https://greensock.com/docs/v3/GSAP/gsap.effects;

import * as gsap from 'gsap';

gsap.registerEffect('explode', (targets, options) => { name: "fade", defaults: { duration: 2 }, //defaults get applied to the "config" object passed to the effect below effect: (targets, config) => { return gsap.to(targets, { duration: config.duration, opacity: 0 }); } });

//now we can use it like this: //gsap.effects.fade(".box");

document.querySelectorAll(".box").forEach(function(box) { box.addEventListener("mouseenter", function() { gsap.effects.fade(this); }); });


Bard stated: 'You are right. The gsap.registerEffect() function is a function. The error message you are getting is a bug in the Node.js implementation of the GreenSock library.

The GreenSock documentation is correct. You can run the code you have written on the GreenSock reference website because the GreenSock library is implemented differently on the website.

I have reported the bug to the Node.js team. They are working on a fix.

In the meantime, you can use the following workaround to register an effect in Node.js:

const gsap = require('gsap');

gsap.registerEffect('explode', (targets, options) => { // This function implements the explode effect. }); The require() function imports the GreenSock library from a Node.js module. The gsap.registerEffect() function registers an effect using the imported library.'


I was testing out Javascript libraries using NodeJS when I ran into an error where NodeJS is not enabling functions within the gsap library: https://greensock.com/docs/v3/GSAP. I am unsure if this is just an issue with NodeJS processing specific GSAP's library functions, or all library functions.

How often does it reproduce? Is there a required condition?

all the time, when running a local .mjs module javascript file using NodeJS. while attempting to utilize the gsap library referenced here: https://greensock.com/docs/v3/GSAP

What is the expected behavior? Why is that the expected behavior?

I don't know, but this is the unexpected behavior that I have seen so far:

PS C:\Users\eorti\Downloads\VSCode> node script.mjs file:///C:/Users/eorti/Downloads/VSCode/script.mjs:3 gsap.registerEffect('explode', function(targets, options) { ^

TypeError: gsap.registerEffect is not a function at file:///C:/Users/eorti/Downloads/VSCode/script.mjs:3:6 at ModuleJob.run (node:internal/modules/esm/module_job:192:25) at async DefaultModuleLoader.import (node:internal/modules/esm/loader:228:24) at async loadESM (node:internal/process/esm_loader:40:7) at async handleMainPromise (node:internal/modules/run_main:66:12)

Node.js v20.5.1 PS C:\Users\eorti\Downloads\VSCode> node script.mjs file:///C:/Users/eorti/Downloads/VSCode/script.mjs:1 gsap.registerEffect({ ^

ReferenceError: gsap is not defined at file:///C:/Users/eorti/Downloads/VSCode/script.mjs:1:1 at ModuleJob.run (node:internal/modules/esm/module_job:192:25) at async DefaultModuleLoader.import (node:internal/modules/esm/loader:228:24) at async loadESM (node:internal/process/esm_loader:40:7) at async handleMainPromise (node:internal/modules/run_main:66:12)

Node.js v20.5.1 PS C:\Users\eorti\Downloads\VSCode> node script.mjs file:///C:/Users/eorti/Downloads/VSCode/script.mjs:3 gsap.registerEffect({ ^

TypeError: gsap.registerEffect is not a function at file:///C:/Users/eorti/Downloads/VSCode/script.mjs:3:6 at ModuleJob.run (node:internal/modules/esm/module_job:192:25) at async DefaultModuleLoader.import (node:internal/modules/esm/loader:228:24) at async loadESM (node:internal/process/esm_loader:40:7) at async handleMainPromise (node:internal/modules/run_main:66:12)

Node.js v20.5.1 PS C:\Users\eorti\Downloads\VSCode> node script.mjs file:///C:/Users/eorti/Downloads/VSCode/script.mjs:3 gsap.registerEffect({ ^

TypeError: gsap.registerEffect is not a function at file:///C:/Users/eorti/Downloads/VSCode/script.mjs:3:6 at ModuleJob.run (node:internal/modules/esm/module_job:192:25) at async DefaultModuleLoader.import (node:internal/modules/esm/loader:228:24) at async loadESM (node:internal/process/esm_loader:40:7) at async handleMainPromise (node:internal/modules/run_main:66:12)

Node.js v20.5.1 PS C:\Users\eorti\Downloads\VSCode> node script.mjs file:///C:/Users/eorti/Downloads/VSCode/script.mjs:3 const gsap = require('gsap'); ^

SyntaxError: Identifier 'gsap' has already been declared at DefaultModuleLoader.moduleStrategy (node:internal/modules/esm/translators:116:18) at DefaultModuleLoader.moduleProvider (node:internal/modules/esm/loader:190:14) at async link (node:internal/modules/esm/module_job:67:21)

Node.js v20.5.1 PS C:\Users\eorti\Downloads\VSCode> node script.mjs file:///C:/Users/eorti/Downloads/VSCode/script.mjs:5 defaults: { ^

SyntaxError: Unexpected token ':' at DefaultModuleLoader.moduleStrategy (node:internal/modules/esm/translators:116:18) at DefaultModuleLoader.moduleProvider (node:internal/modules/esm/loader:190:14) at async link (node:internal/modules/esm/module_job:67:21)

Node.js v20.5.1 PS C:\Users\eorti\Downloads\VSCode> node -v v20.5.1

What do you see instead?

I don't know, but this is the unexpected behavior that I have seen so far:

PS C:\Users\eorti\Downloads\VSCode> node script.mjs file:///C:/Users/eorti/Downloads/VSCode/script.mjs:3 gsap.registerEffect('explode', function(targets, options) { ^

TypeError: gsap.registerEffect is not a function at file:///C:/Users/eorti/Downloads/VSCode/script.mjs:3:6 at ModuleJob.run (node:internal/modules/esm/module_job:192:25) at async DefaultModuleLoader.import (node:internal/modules/esm/loader:228:24) at async loadESM (node:internal/process/esm_loader:40:7) at async handleMainPromise (node:internal/modules/run_main:66:12)

Node.js v20.5.1 PS C:\Users\eorti\Downloads\VSCode> node script.mjs file:///C:/Users/eorti/Downloads/VSCode/script.mjs:1 gsap.registerEffect({ ^

ReferenceError: gsap is not defined at file:///C:/Users/eorti/Downloads/VSCode/script.mjs:1:1 at ModuleJob.run (node:internal/modules/esm/module_job:192:25) at async DefaultModuleLoader.import (node:internal/modules/esm/loader:228:24) at async loadESM (node:internal/process/esm_loader:40:7) at async handleMainPromise (node:internal/modules/run_main:66:12)

Node.js v20.5.1 PS C:\Users\eorti\Downloads\VSCode> node script.mjs file:///C:/Users/eorti/Downloads/VSCode/script.mjs:3 gsap.registerEffect({ ^

TypeError: gsap.registerEffect is not a function at file:///C:/Users/eorti/Downloads/VSCode/script.mjs:3:6 at ModuleJob.run (node:internal/modules/esm/module_job:192:25) at async DefaultModuleLoader.import (node:internal/modules/esm/loader:228:24) at async loadESM (node:internal/process/esm_loader:40:7) at async handleMainPromise (node:internal/modules/run_main:66:12)

Node.js v20.5.1 PS C:\Users\eorti\Downloads\VSCode> node script.mjs file:///C:/Users/eorti/Downloads/VSCode/script.mjs:3 gsap.registerEffect({ ^

TypeError: gsap.registerEffect is not a function at file:///C:/Users/eorti/Downloads/VSCode/script.mjs:3:6 at ModuleJob.run (node:internal/modules/esm/module_job:192:25) at async DefaultModuleLoader.import (node:internal/modules/esm/loader:228:24) at async loadESM (node:internal/process/esm_loader:40:7) at async handleMainPromise (node:internal/modules/run_main:66:12)

Node.js v20.5.1 PS C:\Users\eorti\Downloads\VSCode> node script.mjs file:///C:/Users/eorti/Downloads/VSCode/script.mjs:3 const gsap = require('gsap'); ^

SyntaxError: Identifier 'gsap' has already been declared at DefaultModuleLoader.moduleStrategy (node:internal/modules/esm/translators:116:18) at DefaultModuleLoader.moduleProvider (node:internal/modules/esm/loader:190:14) at async link (node:internal/modules/esm/module_job:67:21)

Node.js v20.5.1 PS C:\Users\eorti\Downloads\VSCode> node script.mjs file:///C:/Users/eorti/Downloads/VSCode/script.mjs:5 defaults: { ^

SyntaxError: Unexpected token ':' at DefaultModuleLoader.moduleStrategy (node:internal/modules/esm/translators:116:18) at DefaultModuleLoader.moduleProvider (node:internal/modules/esm/loader:190:14) at async link (node:internal/modules/esm/module_job:67:21)

Node.js v20.5.1 PS C:\Users\eorti\Downloads\VSCode> node -v v20.5.1

Additional information

No response

bnoordhuis commented 1 year ago

Not a node bug. Maybe a bug in that library but this is not the place to report 3rd party bugs.