Saturday, 25 July 2020

Different ES6 “import” behavior between ESM Loader and Webpack?

Hi! I’m currently building a 3D multiplayer web game where my frontend consists of ES6 modules bundled with Webpack+babel. My backend uses vanilla node with the experimental ES6 module compatibility.One of my modules is used by both the client and the server, as they both need a copy of the game.This module uses three.js, but the problem is that when I try to include three using import * as THREE from “three”, THREE.Vector3 is apparently undefined on my node server while it works properly on the client.On the other hand, when I try to include three.js using import THREE from “three”, the opposite happens. THREE.Vector3 is defined on the server properly, but on the client it is undefined...Why does this discrepancy occur and how can I make it so that my module can be used on both the client and my node backend?

Submitted July 25, 2020 at 10:16PM by santoso-sheep

No comments:

Post a Comment