jnsmalm / pixi3d

The 3D renderer for PixiJS. Seamless integration with 2D applications.
https://pixi3d.org
MIT License
759 stars 44 forks source link

Esm 5 target #109

Closed GordonTombola closed 2 years ago

GordonTombola commented 2 years ago

failure to extends classes from pixi3d when using es5 and esm if the target is set to es2017

error was: TypeError: Class constructor Container3D cannot be invoked without 'new'

jnsmalm commented 2 years ago

Traveling, can take a look after a week or so.

jnsmalm commented 2 years ago

Could you please provide some steps so I can try to reproduce this error?

GordonTombola commented 2 years ago

Could you please provide some steps so I can try to reproduce this error?

By exporting the project as ES2017 you're asking any consumer of the package that targets lower than this ES spec (which is large amount of people) to transpile a node_module via webpack/typescript/rollup etc. which is generally considered bad practice. In most cases packages export the following:

I build out pixi3d's dist and types and copy and replace my existing dist/types folder in my project's node_modules/pixi3d folder. When my tsconfig in my project is set to target es5 (for greater browser compatibility), pixi3d's es target is too high for the underlying javascript to attempt to extend the classes within pixi3d

example tsconfig for my project:

{
    "compilerOptions": {
        "target": "es5",
        "module": "es2020",
        "moduleResolution": "node",
        "allowJs": false,
        "strict": true,
        "sourceMap": false,
        "allowSyntheticDefaultImports": true,
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "strictPropertyInitialization": false,
        "resolveJsonModule": true,
        "noUnusedLocals": false,
        "lib": [
            "es5",
            "es2015",
            "es2016",
            "es2017",
            "dom",
            "ES2020.String"
        ],
        "typeRoots": [
            "../../node_modules/@types",
            "./node_modules/@types",
            "./typings"
        ],
        "outDir": "./dist/esm/"
    },
    "include": [
        "./src/**/*",
        "./typings/**/*"
    ],
    "exclude": [
        "../../node_modules",
        "./node_modules",
        "./**/*.spec.ts"
    ]
}

example of container3d with your current settings:

image

example with my settings change:

image
jnsmalm commented 2 years ago

Got it, thanks!

What happened to the package-lock file in this commit? Can you revert those changes?

GordonTombola commented 2 years ago

Got it, thanks!

What happened to the package-lock file in this commit? Can you revert those changes?

sorted, must have happened when I ran npm install