tinygames icon indicating copy to clipboard operation
tinygames copied to clipboard

"Super expression must either be null or a function" when trying to extend Renderer in test

Open ericjang opened this issue 4 years ago • 1 comments

Hi, thanks for putting this awesome repo together. I'm new to the Node/Babel/ES6/Mocha/Webpack ecosystem, so please bear with my novice question:

I added a file wiggle/test/client.js with the following contents:

import WiggleRenderer from '../src/client/WiggleRenderer'

Then I ran ./node_modules/.bin/mocha --require @babel/register ./test/client.js

This causes the error


Browserslist: caniuse-lite is outdated. Please run next command `npm update caniuse-lite browserslist`

TypeError: Super expression must either be null or a function
    at _inherits (C:\Users\ejang-pc\source\repos\tinygames\wiggle\src\client\WiggleRenderer.js:36:113)
    at C:\Users\ejang-pc\source\repos\tinygames\wiggle\src\client\WiggleRenderer.js:46:3
    at Object.<anonymous> (C:\Users\ejang-pc\source\repos\tinygames\wiggle\src\client\WiggleRenderer.js:194:2)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Module._compile (C:\Users\ejang-pc\source\repos\tinygames\wiggle\node_modules\pirates\lib\index.js:99:24)
    at Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Object.newLoader [as .js] (C:\Users\ejang-pc\source\repos\tinygames\wiggle\node_modules\pirates\lib\index.js:104:7)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (C:\Users\ejang-pc\source\repos\tinygames\wiggle\test\/client.js:5:1)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Module._compile (C:\Users\ejang-pc\source\repos\tinygames\wiggle\node_modules\pirates\lib\index.js:99:24)
    at Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Object.newLoader [as .js] (C:\Users\ejang-pc\source\repos\tinygames\wiggle\node_modules\pirates\lib\index.js:104:7)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.exports.requireOrImport (C:\Users\ejang-pc\source\repos\tinygames\wiggle\node_modules\mocha\lib\esm-utils.js:20:12)
    at Object.exports.loadFilesAsync (C:\Users\ejang-pc\source\repos\tinygames\wiggle\node_modules\mocha\lib\esm-utils.js:33:34)
    at Mocha.loadFilesAsync (C:\Users\ejang-pc\source\repos\tinygames\wiggle\node_modules\mocha\lib\mocha.js:431:19)
    at singleRun (C:\Users\ejang-pc\source\repos\tinygames\wiggle\node_modules\mocha\lib\cli\run-helpers.js:125:15)
    at exports.runMocha (C:\Users\ejang-pc\source\repos\tinygames\wiggle\node_modules\mocha\lib\cli\run-helpers.js:190:10)
    at Object.exports.handler (C:\Users\ejang-pc\source\repos\tinygames\wiggle\node_modules\mocha\lib\cli\run.js:362:11)
    at C:\Users\ejang-pc\source\repos\tinygames\wiggle\node_modules\mocha\node_modules\yargs\lib\command.js:241:49
npm ERR! Test failed.  See above for more details.

Notably, this error does not occur when I define export default class for other base classes, e.g. the issue described here: https://stackoverflow.com/questions/35777991/typeerror-super-expression-must-be-null-or-a-function-not-undefined-with-babel

The error only seems to show up when I define subclasses of lance's Renderer.

Babel seems to transpile the WiggleRenderer.js file just fine when building the main binary, but for some reason it fails when doing it for the test. Any suggestions on what to try?

I filed this bug here because maybe there is something I am not fully understanding about webpack or babel or the mocha test environment. Any tips on what I could try would be greatly appreciated!

ericjang avatar Dec 25 '20 21:12 ericjang

I was able to narrow down this issue a bit further - the issue is that require('lance-gg') is somehow loading the server-side library. How do I load the client-side library instead?

https://stackoverflow.com/questions/65755989/how-does-lance-gg-know-whether-to-load-the-client

ericjang avatar Jan 17 '21 00:01 ericjang