-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Fix ES usage in node #5522
Fix ES usage in node #5522
Conversation
@@ -40,7 +40,7 @@ | |||
"deep-assign": "^2.0.0", | |||
"load-bmfont": "^1.2.3", | |||
"super-animejs": "^3.1.0", | |||
"super-three": "0.164.0", | |||
"three": "npm:super-three@0.164.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just asked chatgpt, this syntax may works only with npm and yarn 1.x, and may not work on yarn 2 or pnpm. I know some of you are using pnpm so we need to verify that. I tried the write a node loader to specify an alias but didn't succeed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was late yesterday for me, so I didn't test with pnpm. Actually it works just fine with it, really don't trust anything that chatgpt is saying, even with gpt-4o, always verify things yourself.
Just tested in the aframe repo, rm -rf node_modules package-lock.json; pnpm install
it works just fine
...
dependencies:
+ buffer 6.0.3
+ debug 4.3.4
+ deep-assign 2.0.0 (3.0.0 is available)
+ load-bmfont 1.4.1
+ super-animejs 3.1.0
+ three <- super-three 0.164.0
+ three-bmfont-text 3.0.0
+ webvr-polyfill 0.10.12
...
Thanks for the detail explanation. Do we need to wait for confirmation that this works with |
src/index.js
Outdated
@@ -80,7 +80,7 @@ require('./extras/primitives/'); | |||
|
|||
console.log('A-Frame Version: 1.5.0 (Date 2024-05-03, Commit #9fe641ce)'); | |||
console.log('THREE Version (https://github.com/supermedium/three.js):', | |||
pkg.dependencies['super-three']); | |||
pkg.dependencies['three']); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would now log the npm alias npm:[email protected]
which isn't really informative to the end user. We could consider THREE.REVISION
instead, although that wouldn't include patch version AFAIK, so for example 0.164.1
would simply become 164
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, THREE.REVISION is probably enough here. I'll make the change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or I can just remove the "npm:super-three@" part with pkg.dependencies['three'].replace('npm:super-three@', '')
so that stays the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually it's better THREE.REVISION. I have potentially a more recent version of super-three with patches in my project, and returning the version specified in aframe dependency is actually confusing.
It might be a good idea to change the code in inspector.js#L19 as well. Although the |
Thanks @mrxz for the feedback, I'll make the two changes you suggested. |
Ok I think it's all good. |
…le, three version may actually be different than the version defined in aframe dependencies
Just to show you what my project looks like using aframe as an ES module. in {
"overrides": {
"three": "vincentfretin/three.js#super-r164-lut",
},
"dependencies": {
"aframe": "aframevr/aframe#81caf89",
"aframe-extras": "^7.3.1",
"three": "vincentfretin/three.js#super-r164-lut"
}
} with currently a patch with this PR changes using patch-package in ...
entry: path.resolve(__dirname, "src/index.js"),
...
plugins: [
new webpack.ProvidePlugin({
Buffer: ["buffer", "Buffer"],
}),
...
],
externals: {
// nothing
} in import "aframe/src/index.js";
import "aframe-extras/controls/index.js";
import "aframe-extras/pathfinding/index.js";
import "aframe-extras/misc/sphere-collider.js"; |
Thanks. Should we explore this? #5363 |
I'm all in to make steps towards using ESM modules everywhere, if I can strip some aframe components I'm not using, or switch the renderer with some other implementation, that's clearly great for me. For no build tools, I don't know if we can achieve that, like @mrxz said in #5363 (comment) there are still some dependencies that aren't ESM. |
That's really awesome to just update in my project "aframe": "aframevr/aframe#08fe993" and be done with the update, still using my three fork. |
We can already start transitioning to In any case, replacing
Totally agreed, but there is a fundamental problem with A-Frame components. They don't communicate their dependencies. Any In an ideal world the dependencies would also be imported using import * as AFRAME from 'aframe';
import { SomeComponent } from 'aframe-some-component';
export const OtherComponent = AFRAME.registerComponent('other-component', {
init: function() {
this.el.setAttribute(SomeComponent, { color: 'red' });
}
}); But everything can be done in gradual steps. Having the code use ESM modules internally while still compiling to a traditional bundle would already be a big step. |
Would like to retain the script tag syntax alongside modules. While modules are useful I still think they are a worse developer experience for casual prototyping and beginners. |
Sorry I had to revert this. It breaks the A-Frame site generation https://github.com/aframevr/aframe-site that only works with old versions of node that don't support the We have to find a way to upgrade the A-Frame site generation or an alternative way for this PR that doesn't enforce a new version of node. |
The npm: prefix feature shouldn't be related to the node version, npm version maybe, and you can upgrade the npm version that comes from the node installation with
and for |
Can you please create an issue of what is blocking you on node 16. You mentioned an old process manager you were using I think last time. Can you give us the command you're currently using to redeploy so we can attempt to fix it. We can probably switch to pm2 if needed. |
Yeah the website generator doesn't support new versions of node. Server that generates the site is on |
6.17.1 of node? wow |
Yes. That's the most modern version I found it works. It's a static site yes and hosted on github pages already. The server monitors for changes in the website repo and deploys the site automatically. Same as we do for the master builds (It's actually the same machine on AWS) |
Feel free to play with it. Thanks so much. If we get search to work again would be awesome but priority is to be able to deploy the site again reliably. |
This is where the A-Frame site is hosted https://github.com/aframevr/aframevr.github.io |
I was able to deploy the website for the new 1.6.0 version. We can remerge this PR once we can make it work with the aframe-site code base. Sorry for having to revert. |
No worry about the revert, we can revert the revert later. I'll put back my patch in my repo in the meantime if I need a later master version. For the bot on the AWS machine, is it using the same node version? We didn't seem to had an issue for the build, so I'm wondering why the aframe site build wasn't working. |
AWS only triggers on github commit. Same as the master build bot. The build bot doesn't depend on the hexo stuff so can run on a newer version of node. If there's a way to run on Github infra instead of AWS would be def better. |
Let's do baby steps, first this issue aframevr/aframe-site#532 |
With aframevr/aframe-site#532 fixed you should be able to update the node/npm version used to build aframe-site by your bot. Even with the old hexo version, the build is successful with node 22. |
Description:
The
npm run test:node
command was broken since we moved to using three ES imports, because ofaframe/src/three.js
that is requiring an ES moduleaframe/src/lib/three.module.js
and that was not supported in node, only working in webpack environment.And using
require('aframe/src')
like described in the documentation https://aframe.io/docs/master/core/globals.html#requiring-aframe-in-a-node-js-environment was also broken.Now that node 22 supports requiring an ES module with
require("somemodule.mjs")
currently behind a--experimental-require-module
flag, see https://nodejs.org/en/blog/announcements/v22-release-announce#support-requireing-synchronous-esm-graphs, I made an attempt to fix it.This also simplify for me using aframe as an ES module with
import "aframe/src/index.js";
and my own super-three version in a webpack project using only the Buffer polyfill in webpack config, I had issues using the process polyfill with some other dependencies. And it was a nightmare to setup a three-mesh-bvh Worker with three imports because the Worker ends up with no three at all when using THREE external and no way to include an aframe build in the Worker.Changes proposed:
lib/three.module.js
tolib/three.mjs
for node module resolution to workrequire('../../vendor/DeviceOrientationControls');
inthree.js
process.browser
andprocess.nextTick
for the tests.isBrowserEnvironment
function to properly check forprocess
undefined, also fix condition for settingwindow.logs
to useisBrowserEnvironment
--experimental-require-module
node flag, works only on node 22