question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Uncaught ReferenceError: exports is not defined

See original GitHub issue

Hi to everyone here, I’m new at phaser editor. I code in Typescript. I want to create a class and import it in level.ts. Bu I got “Uncaught ReferenceError: exports is not defined” message at browser’s console. My code is this: `///<reference path="ShapeControllerHTMLV1.ts" />

import { shapeController } from “./ShapeControllerHTMLV1”;

class Level extends Phaser.State {

constructor() {
	
	super();
	
}

init() {
	
	this.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;
	this.scale.pageAlignHorizontally = true;
	this.scale.pageAlignVertically = true;
	
}

preload () {
	
	this.load.pack('section0', 'assets/pack.json');
	
}

create() {
    var a = new shapeController.Greeter(this.game, 10, 10, 'blabla');
	
}

}And this is my class:export namespace shapeController{ export class Greeter extends Phaser.Sprite{ constructor(gm:Phaser.Game, _x:number, _y:number, _name:string){ super(gm, _x, _y, _name); } }
}`

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
PhaserEditor2Dcommented, Jan 16, 2018

Ok, look this answer here:

https://stackoverflow.com/questions/43472778/typescript-exports-is-not-defined

It is as I said in the last comment. If you want to avoid that exception:

  • Use a third-party module loader.
  • Or don’t use any import/export keywords, just keep everything in the global scope.

Note if you use the second option you have to load all the js files in your index.html file or as script assets in the assets-pack.json file.

0reactions
PhaserEditor2Dcommented, Jan 16, 2018

I am looking this. It think when you use import/export the target module system should support it. For example, you should include commonjs in your project. I have not too much experience with TypeScript, let me do a litte more research.

Thanks for send the project, it is helping a lot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript ReferenceError: exports is not defined
I had the error "exports is not defined" coming from an imported NPM module. Changing my typescript config did nothing as I had...
Read more >
How to fix ReferenceError: exports is not defined TypeScript
If you are getting the error for code that runs in the browser, try defining a global exports variable above the script tags...
Read more >
Uncaught ReferenceError: exports is not defined : r/typescript
Getting this error for some dumb reason i'm sure. Uncaught ReferenceError: exports is not defined. at app.js:2. (anonymous) @ app.js:2. all ...
Read more >
exports is not defined" in browser : WEB-26773 - YouTrack
Typescript compiler outputs wrong javascript module format, giving "ReferenceError: exports is not defined" in browser ; "use strict"; Object.defineProperty ...
Read more >
Uncaught ReferenceError: exports is not defined #27 - GitHub
When I try to import I get the Uncaught ReferenceError: exports is not defined . I've tried several solutions found on Stackoverflow and ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found