jrouwe / JoltPhysics.js

Port of JoltPhysics to JavaScript using emscripten
MIT License
270 stars 21 forks source link

import with webpack #52

Closed kutu closed 11 months ago

kutu commented 11 months ago
import Jolt from 'jolt-physics'

getting error

ERROR in ./js/game/test.coffee 17:0-36
Module not found: Error: Default condition should be last one

fixing it by modifing package.json from

"exports": {
    ".": {
      "default": "./dist/jolt-physics.wasm-compat.js",
      "types": "./dist/jolt-physics.wasm-compat.d.ts"
    },

to

"exports": {
    ".": {
      "types": "./dist/jolt-physics.wasm-compat.d.ts",
      "default": "./dist/jolt-physics.wasm-compat.js"
    },

default is last now (why? dont know)

then getting error

  ERROR in ../node_modules/jolt-physics/dist/jolt-physics.js 21:20-36
  Module not found: Error: Can't resolve 'module' in 'D:\projects\js\test\node_modules\jolt-physics\dist'

  ERROR in ../node_modules/jolt-physics/dist/jolt-physics.js 21:172-201
  Module not found: Error: Can't resolve './' in 'D:\projects\js\test\node_modules\jolt-physics\dist'

I guess webpack doesn't like this parts

await import("module")

and

new URL("./",import.meta.url)

If I don't import Jolt into my code, then I will not have auto-completion.

I did read that you are not into JS world, so asking other people who can help here. Thanks.

jrouwe commented 11 months ago

Sorry, I indeed cannot help you here.

Maybe @isaac-mason has an opinion on swapping default and types (he added TS support)?

The await import("module") and new URL("./",import.meta.url) statements are created by emscripten, so I'm not sure why they would cause a problem.

kutu commented 11 months ago

i was digging this today, and found out that js files you provide are ESM files, means they need to be executed in html with <script type="module" I'm looking for the old way, which is called CommonJS

Emscripten compiles it as "module" using this args https://github.com/jrouwe/JoltPhysics.js/blob/9c086477c412fe42f7e30c7e938bd9ddd9a0bfce/CMakeLists.txt#L49-L51

If you could provide another bundles along side with "module" one, but without EXPORT_ES6 and with/without MODULARIZE, people usually make filenames like mylib.es.js mylib.umd.js mylib.cjs.js

I tried to build this myself, but I'm on Windows, after successfully executed this command cmake -B Build/Distribution -DCMAKE_BUILD_TYPE=Distribution the next one cmake --build Build/Distribution failed with error

MSBuild version 17.8.3+195e7f5a3 for .NET Framework

  Checking Build System
  Generating JoltPhysics.js bindings
  Building Custom Rule H:/1/JoltPhysics.js/CMakeLists.txt
  Building JoltPhysics.js bindings
  Building Custom Rule H:/1/JoltPhysics.js/Build/Distribution/_deps/joltphysics-src/Build/CMakeLists.txt
cl : command line  error D8021: invalid numeric argument '/Werror' [H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-build\Jolt.vcxproj]

i went to H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Build\CMakeLists.txt and commented line 134 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror") and get this error

Details ``` CMake is re-running because H:/1/JoltPhysics.js/Build/Distribution/_deps/joltphysics-build/CMakeFiles/generate.stamp is out-of-date. the file 'H:/1/JoltPhysics.js/Build/Distribution/_deps/joltphysics-src/Build/CMakeLists.txt' is newer than 'H:/1/JoltPhysics.js/Build/Distribution/_deps/joltphysics-build/CMakeFiles/generate.stamp.depend' result='-1' -- Configuring done -- Generating done -- Build files have been written to: H:/1/JoltPhysics.js/Build/Distribution MSBuild version 17.8.3+195e7f5a3 for .NET Framework Checking Build System Building Custom Rule H:/1/JoltPhysics.js/CMakeLists.txt Building Custom Rule H:/1/JoltPhysics.js/Build/Distribution/_deps/joltphysics-src/Build/CMakeLists.txt cl : command line warning D9002: ignoring unknown option '-g' [H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-build\Jolt.vcxproj] cl : command line warning D9002: ignoring unknown option '-ffp-model=precise' [H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-build\Jolt.vcxproj] cl : command line warning D9002: ignoring unknown option '-std=c++17' [H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-build\Jolt.vcxproj] cmake_pch.hxx.cxx H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-build\CMakeFiles\Jolt.dir\Debug\cmake_pch.hxx(3,9): warning C4068: unknown pragma 'clang' [H:\1\JoltPhy sics.js\Build\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Core\Core.h(414,12): error C2039: 'string_view': is not a member of 'std' [H:\1\JoltPhysics.js \Build\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.38.33130\include\algorithm(81,1): see declaration of 'std' H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Core\Core.h(414,1): error C2873: 'string_view': symbol cannot be used in a using-declaration [ H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Float4.h(13,2): error C2039: 'align_val_t': is not a member of 'std' [H:\1\JoltPhysics.js \Build\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.38.33130\include\algorithm(81,1): see declaration of 'std' H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Float4.h(13,2): error C2061: syntax error: identifier 'align_val_t' [H:\1\JoltPhysics.js\ Build\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Float4.h(13,2): error C2535: 'void *JPH::Float4::operator new(size_t)': member function a lready defined or declared [H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Float4.h(13,2): see declaration of 'JPH::Float4::operator new' H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Float4.h(13,2): warning C5051: attribute [[maybe_unused]] requires at least '/std:c++17'; ignored [H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Float4.h(13,2): error C2535: 'void JPH::Float4::operator delete(void *) noexcept': member function already defined or declared [H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Float4.h(13,2): see declaration of 'JPH::Float4::operator delete' H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Float4.h(13,2): error C2535: 'void *JPH::Float4::operator new[](size_t)': member function already defined or declared [H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Float4.h(13,2): see declaration of 'JPH::Float4::operator new[]' H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Float4.h(13,2): error C2535: 'void JPH::Float4::operator delete[](void *) noexcept': memb er function already defined or declared [H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Float4.h(13,2): see declaration of 'JPH::Float4::operator delete[]' H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Float4.h(13,2): error C2065: 'inAlignment': undeclared identifier [H:\1\JoltPhysics.js\Bu ild\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Vec4.h(16,2): error C2039: 'align_val_t': is not a member of 'std' [H:\1\JoltPhysics.js\B uild\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.38.33130\include\algorithm(81,1): see declaration of 'std' H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Vec4.h(16,2): error C2061: syntax error: identifier 'align_val_t' [H:\1\JoltPhysics.js\Bu ild\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Vec4.h(16,2): error C2535: 'void *JPH::Vec4::operator new(size_t)': member function alrea dy defined or declared [H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Vec4.h(16,2): see declaration of 'JPH::Vec4::operator new' H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Vec4.h(16,2): warning C5051: attribute [[maybe_unused]] requires at least '/std:c++17'; i gnored [H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Vec4.h(16,2): error C2535: 'void JPH::Vec4::operator delete(void *) noexcept': member fun ction already defined or declared [H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Vec4.h(16,2): see declaration of 'JPH::Vec4::operator delete' H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Vec4.h(16,2): error C2535: 'void *JPH::Vec4::operator new[](size_t)': member function alr eady defined or declared [H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Vec4.h(16,2): see declaration of 'JPH::Vec4::operator new[]' H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Vec4.h(16,2): error C2535: 'void JPH::Vec4::operator delete[](void *) noexcept': member f unction already defined or declared [H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Vec4.h(16,2): see declaration of 'JPH::Vec4::operator delete[]' H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Vec4.h(16,2): error C2065: 'inAlignment': undeclared identifier [H:\1\JoltPhysics.js\Buil d\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Float3.h(15,2): error C2039: 'align_val_t': is not a member of 'std' [H:\1\JoltPhysics.js \Build\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.38.33130\include\algorithm(81,1): see declaration of 'std' H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Float3.h(15,2): error C2061: syntax error: identifier 'align_val_t' [H:\1\JoltPhysics.js\ Build\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Float3.h(15,2): error C2535: 'void *JPH::Float3::operator new(size_t)': member function a lready defined or declared [H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Float3.h(15,2): see declaration of 'JPH::Float3::operator new' H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Float3.h(15,2): warning C5051: attribute [[maybe_unused]] requires at least '/std:c++17'; ignored [H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Float3.h(15,2): error C2535: 'void JPH::Float3::operator delete(void *) noexcept': member function already defined or declared [H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Float3.h(15,2): see declaration of 'JPH::Float3::operator delete' H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Float3.h(15,2): error C2535: 'void *JPH::Float3::operator new[](size_t)': member function already defined or declared [H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Float3.h(15,2): see declaration of 'JPH::Float3::operator new[]' H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Float3.h(15,2): error C2535: 'void JPH::Float3::operator delete[](void *) noexcept': memb er function already defined or declared [H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Float3.h(15,2): see declaration of 'JPH::Float3::operator delete[]' H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Float3.h(15,2): error C2065: 'inAlignment': undeclared identifier [H:\1\JoltPhysics.js\Bu ild\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Vec3.h(18,2): error C2039: 'align_val_t': is not a member of 'std' [H:\1\JoltPhysics.js\B uild\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Float3.h(50,1): see declaration of 'std' H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Vec3.h(18,2): error C2061: syntax error: identifier 'align_val_t' [H:\1\JoltPhysics.js\Bu ild\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Vec3.h(18,2): error C2535: 'void *JPH::Vec3::operator new(size_t)': member function alrea dy defined or declared [H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Vec3.h(18,2): see declaration of 'JPH::Vec3::operator new' H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Vec3.h(18,2): warning C5051: attribute [[maybe_unused]] requires at least '/std:c++17'; i gnored [H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Vec3.h(18,2): error C2535: 'void JPH::Vec3::operator delete(void *) noexcept': member fun ction already defined or declared [H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Vec3.h(18,2): see declaration of 'JPH::Vec3::operator delete' H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Vec3.h(18,2): error C2535: 'void *JPH::Vec3::operator new[](size_t)': member function alr eady defined or declared [H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Vec3.h(18,2): see declaration of 'JPH::Vec3::operator new[]' H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Vec3.h(18,2): error C2535: 'void JPH::Vec3::operator delete[](void *) noexcept': member f unction already defined or declared [H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Vec3.h(18,2): see declaration of 'JPH::Vec3::operator delete[]' H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Vec3.h(18,2): error C2065: 'inAlignment': undeclared identifier [H:\1\JoltPhysics.js\Buil d\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\UVec4.h(14,2): error C2039: 'align_val_t': is not a member of 'std' [H:\1\JoltPhysics.js\ Build\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Float3.h(50,1): see declaration of 'std' H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\UVec4.h(14,2): error C2061: syntax error: identifier 'align_val_t' [H:\1\JoltPhysics.js\B uild\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\UVec4.h(14,2): error C2535: 'void *JPH::UVec4::operator new(size_t)': member function alr eady defined or declared [H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\UVec4.h(14,2): see declaration of 'JPH::UVec4::operator new' H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\UVec4.h(14,2): warning C5051: attribute [[maybe_unused]] requires at least '/std:c++17'; ignored [H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\UVec4.h(14,2): error C2535: 'void JPH::UVec4::operator delete(void *) noexcept': member f unction already defined or declared [H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\UVec4.h(14,2): see declaration of 'JPH::UVec4::operator delete' H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\UVec4.h(14,2): error C2535: 'void *JPH::UVec4::operator new[](size_t)': member function a lready defined or declared [H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\UVec4.h(14,2): see declaration of 'JPH::UVec4::operator new[]' H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\UVec4.h(14,2): error C2535: 'void JPH::UVec4::operator delete[](void *) noexcept': member function already defined or declared [H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\UVec4.h(14,2): see declaration of 'JPH::UVec4::operator delete[]' H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\UVec4.h(14,2): error C2065: 'inAlignment': undeclared identifier [H:\1\JoltPhysics.js\Bui ld\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Mat44.h(15,2): error C2039: 'align_val_t': is not a member of 'std' [H:\1\JoltPhysics.js\ Build\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Vec3.inl(14,1): see declaration of 'std' H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Mat44.h(15,2): error C2061: syntax error: identifier 'align_val_t' [H:\1\JoltPhysics.js\B uild\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Mat44.h(15,2): error C2535: 'void *JPH::Mat44::operator new(size_t)': member function alr eady defined or declared [H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Mat44.h(15,2): see declaration of 'JPH::Mat44::operator new' H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Mat44.h(15,2): warning C5051: attribute [[maybe_unused]] requires at least '/std:c++17'; ignored [H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Mat44.h(15,2): error C2535: 'void JPH::Mat44::operator delete(void *) noexcept': member f unction already defined or declared [H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Mat44.h(15,2): see declaration of 'JPH::Mat44::operator delete' H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Mat44.h(15,2): error C2535: 'void *JPH::Mat44::operator new[](size_t)': member function a lready defined or declared [H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Mat44.h(15,2): see declaration of 'JPH::Mat44::operator new[]' H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Mat44.h(15,2): error C2535: 'void JPH::Mat44::operator delete[](void *) noexcept': member function already defined or declared [H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Mat44.h(15,2): see declaration of 'JPH::Mat44::operator delete[]' H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Mat44.h(15,2): error C2065: 'inAlignment': undeclared identifier [H:\1\JoltPhysics.js\Bui ld\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Quat.h(35,2): error C2039: 'align_val_t': is not a member of 'std' [H:\1\JoltPhysics.js\B uild\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Vec3.inl(14,1): see declaration of 'std' H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Quat.h(35,2): error C2061: syntax error: identifier 'align_val_t' [H:\1\JoltPhysics.js\Bu ild\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Quat.h(35,2): error C2535: 'void *JPH::Quat::operator new(size_t)': member function alrea dy defined or declared [H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Quat.h(35,2): see declaration of 'JPH::Quat::operator new' H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Quat.h(35,2): warning C5051: attribute [[maybe_unused]] requires at least '/std:c++17'; i gnored [H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Quat.h(35,2): error C2535: 'void JPH::Quat::operator delete(void *) noexcept': member fun ction already defined or declared [H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Quat.h(35,2): see declaration of 'JPH::Quat::operator delete' H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Quat.h(35,2): error C2535: 'void *JPH::Quat::operator new[](size_t)': member function alr eady defined or declared [H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Quat.h(35,2): see declaration of 'JPH::Quat::operator new[]' H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Quat.h(35,2): error C2535: 'void JPH::Quat::operator delete[](void *) noexcept': member f unction already defined or declared [H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Quat.h(35,2): see declaration of 'JPH::Quat::operator delete[]' H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Quat.h(35,2): error C2065: 'inAlignment': undeclared identifier [H:\1\JoltPhysics.js\Buil d\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Double3.h(15,2): error C2039: 'align_val_t': is not a member of 'std' [H:\1\JoltPhysics.j s\Build\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Vec3.inl(14,1): see declaration of 'std' H:\1\JoltPhysics.js\Build\Distribution\_deps\joltphysics-src\Jolt\Math\Double3.h(15,2): error C1003: error count exceeds 100; stopping compilation [H:\1\JoltPhy sics.js\Build\Distribution\_deps\joltphysics-build\Jolt.vcxproj] (compiling source file 'CMakeFiles/Jolt.dir/cmake_pch.hxx.cxx') ```
isaac-mason commented 11 months ago

Looks like the typescript docs do say "types" should come first, I can cut a PR to fix this. It seems that not all bundlers complain about this.

The "types" condition should always come first in "exports".

https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-7.html#packagejson-exports-imports-and-self-referencing

isaac-mason commented 11 months ago

Re adding a CommonJS build, I'm happy to help with this if there's interest!

I suggested starting with only publishing ESM as it's the modern format, and there is some effort in supporting both.

isaac-mason commented 11 months ago

Also re your immediate issue, what version of webpack are you using? And do you mind sharing your config?

The latest versions of webpack (iirc 4 and 5) should support ESM.

kutu commented 11 months ago

I use latest webpack

This is minimal example to reproduce the problems example.zip

> npm i
> npm run build

after that you will need to fix types and default order to get the second error

isaac-mason commented 11 months ago

Thanks! I'll take a look soon

isaac-mason commented 11 months ago

I've found that with the following changes, the minimal webpack repro builds successfully:

It appears this isn't an issue with commonjs vs esm, but an issue with webpack not handling the node-specific code that emscripten adds when node is included in the ENVIRONMENT argument.

In another emscripten package recast-navigation-js, I use the argument -s ENVIRONMENT='web' (not specifying node), and the package works fine in node environments.

I'll do some testing later today checking if node is unaffected by this change. If it still works ok, I'll create a PR which should resolve this webpack issue πŸ™‚

isaac-mason commented 11 months ago

With the above change, the wasm-compat (default) flavour works with node, but the wasm flavour breaks, seemingly because node's built-in fetch method is not fully implemented?

node:internal/deps/undici/undici:11372
    Error.captureStackTrace(err, this);
          ^

TypeError: fetch failed
    at Object.fetch (node:internal/deps/undici/undici:11372:11) {
  cause: Error: not implemented... yet...
      at makeNetworkError (node:internal/deps/undici/undici:4801:35)
      at schemeFetch (node:internal/deps/undici/undici:9531:18)
      at node:internal/deps/undici/undici:9409:26
      at mainFetch (node:internal/deps/undici/undici:9428:11)
      at fetching (node:internal/deps/undici/undici:9377:7)
      at fetch2 (node:internal/deps/undici/undici:9245:20)
      at Object.fetch (node:internal/deps/undici/undici:11370:18)
      at fetch (node:internal/process/pre_execution:282:25)
      at Ia (file:///Users/isaacmason/Development/JoltPhysics.js/dist/jolt-physics.wasm.js:15:133)
      at file:///Users/isaacmason/Development/JoltPhysics.js/dist/jolt-physics.wasm.js:43:160
}

Node.js v20.9.0

I'll keep investigating!

Reading through some emscripten and webpack issues, having separate node and web builds is a commonly suggested solution πŸ™

isaac-mason commented 11 months ago

@kutu I don't have a proper solve yet, but I can share a workaround for using JoltPhysics.js with webpack 5.

These issues appear to be common for emscripten packages that target both web and node environments - I found this workaround from ammo.js github issues discussing similar webpack issues.

Once the fix in #54 is released, this webpack configuration should mitigate the issues webpack has with the node environment-specific code generated by emscripten (see resolve.fallback.module):

const path = require("path");

module.exports = {
  mode: "production",
  entry: "./main.js",
  output: {
    filename: "main.js",
    path: path.resolve(__dirname, "dist"),
  },
  resolve: {
    fallback: {
      module: false,
    },
  },
};

This still outputs one error though:

ERROR in ./node_modules/jolt-physics/dist/jolt-physics.wasm-compat.js 12:178-207
Module not found: Error: Can't resolve './' in '/Users/isaacmason/Downloads/example/node_modules/jolt-physics/dist'
resolve './' in '/Users/isaacmason/Downloads/example/node_modules/jolt-physics/dist'
  Parsed request is a directory
  using description file: /Users/isaacmason/Downloads/example/node_modules/jolt-physics/package.json (relative path: ./dist)
    using description file: /Users/isaacmason/Downloads/example/node_modules/jolt-physics/package.json (relative path: ./dist)
      as directory
        existing directory /Users/isaacmason/Downloads/example/node_modules/jolt-physics/dist
          using description file: /Users/isaacmason/Downloads/example/node_modules/jolt-physics/package.json (relative path: ./dist)
            using path: /Users/isaacmason/Downloads/example/node_modules/jolt-physics/dist/index
              using description file: /Users/isaacmason/Downloads/example/node_modules/jolt-physics/package.json (relative path: ./dist/index)
                no extension
                  /Users/isaacmason/Downloads/example/node_modules/jolt-physics/dist/index doesn't exist
 @ ./main.js 1:0-32 3:19-23

This error doesn't prevent the bundle from being generated, and seemingly doesn't break the bundle - jolt-physics can be imported and used fine (I tested with the wasm-compat flavour). To silence this error, you could write a basic plugin, e.g.

const path = require("path");

class FilterErrorsPlugin {
  constructor(filter) {
    this.filter = new RegExp(filter);
  }

  apply(compiler) {
    compiler.hooks.done.tap("FilterErrorsPlugin", (stats) => {
      stats.compilation.errors = stats.compilation.errors.filter((error) => {
        return !this.filter.test(error.message);
      });
    });
  }
}

module.exports = {
  mode: "production",
  entry: "./main.js",
  output: {
    filename: "main.js",
    path: path.resolve(__dirname, "dist"),
  },
  resolve: {
    fallback: {
      module: false,
    },
  },
  plugins: [
    new FilterErrorsPlugin("Can't resolve '\\./' in '.+/jolt-physics/dist'"),
  ],
};

I recognise these workarounds aren't ideal! As I get time I'll keep investigating what the path forward should be.

Let me know if this helps in the meantime πŸ™‚

kutu commented 11 months ago

yes, it works, thank you for your time.

HunterBarclay commented 9 months ago

@isaac-mason Will there be separate web and node builds made available, or will users just have to use the webpack config fix?

isaac-mason commented 9 months ago

@KyroVibe we don't have a clear path forward for this yet. Doubling the amount of builds we need to support isn't ideal.

For the moment using the above fix is still what I'd recommend. Or if you really need an environment specific build, you can build JoltPhysics.js yourself with different configuration.

HunterBarclay commented 9 months ago

@isaac-mason Yeah, I've just been building it myself so far. Thank you