using typescript 3.0.1
module : commonjs
target : es5
.TS
import firebase from 'firebase'
.JS
Object.defineProperty(exports, "__esModule", { value: true });
browser error:
Uncaught ReferenceError: require is not defined
That looks like a runtime error, not a type error. You probably have --module commonJs set and need to choose a different module system that will work in your browser.
@andy-ms I tried in both Chrome and Safari
I tried all available modules and none solved the error for me.
here is the safari error: ReferenceError: Can't find variable: require
Please let me know if I can provide anything that would help.
That's not a compiler bug, that's a JavaScript runtime error. When TypeScript compiles to commonjs modules it uses the require function that is available in node.js. In the browser you'll need to set up a different module system.
Ok.. but what if I have this problem just running via ts-node from a CLI with no browser?
I'm back.
FIX for this issue for me was to go from node 13 to node 12
I just started trying node 13 yesterday, so this was a surprise.
After 3 hours, it dawned on me to try just running a simple .js file with node. Same error.
Switched versions, and this particular issue went away.
At some point, I will research WHY node 13 does this. For now, I have work to do.
@bobbwhy I'm on v12.13.1, and this still happens to me? Except it isn't in a browser, but in Electron. I also got a Uncaught ReferenceError: exports is not defined error, but I fixed it using a little hack (which I would like not to use):
<script>var exports = {};</script>